当前位置: 首页 > 知识库问答 >
问题:

在php中清空$ray[]的旧值

危卜鹰
2023-03-14

我正在尝试删除我在internet上搜索的数组的旧值。我刚刚找到了使用此解决方案的unset()方法,但我的情况似乎有所不同。下面是我的完整代码

<?php



header('Content-type: application/json; charset=utf-8');
$link = mysqli_connect("localhost","root","");
mysqli_query($link,"SET NAMES UTF8");
$db= mysqli_select_db($link,"Mirsa") or die("Cannot select Database.");



 if (isset($_GET['Product_ID']) ){
   $productId;
    $Menu_ID =$_GET['Product_ID'];



$query = "SELECT 
   mirsaProductId,mirsaProductCode,mirsaProductDescription,
   mirsaProductPcsInCartoon,mirsaProductWeight,mirsaProductVolume,
    mirsaProductCodeBType,mirsaProductCodeCType,FK_mirsaCategoryId 
   from mirsaProduct WHERE FK_mirsaCategoryId='$Menu_ID'";



    $result = mysqli_query($link,$query) or die(mysql_error($link));

                $response["Products"] = array();
                $products = array();
         while ($row = mysqli_fetch_array($result)) {
                $image[]=array()         
                $products["mirsaProductId"] =          $row["mirsaProductId"];
                $products["mirsaProductCode"]         = $row["mirsaProductCode"];
                $products["mirsaProductDescription"]  = $row["mirsaProductDescription"];
                $products["mirsaProductPcsInCartoon"] = $row["mirsaProductPcsInCartoon"];
                $products["mirsaProductWeight"] =      $row["mirsaProductWeight"];
                $products["mirsaProductVolume"] =       $row["mirsaProductVolume"];
                $products["mirsaProductCodeBType"] =   $row["mirsaProductCodeBType"];
                $products["mirsaProductCodeCType"] =   $row["mirsaProductCodeCType"];
                $productId = $row["mirsaProductId"];




$query2 = "SELECT mirsaProductUrlImage FROM mirsaProduct,mirsaProductImages
WHERE FK_mirsaProductId = '$productId' GROUP BY mirsaProductUrlImage";     

    $result2=mysqli_query($link, $query2);
    while ($row2 = mysqli_fetch_array($result2))
      {
             $image [] = $row2["mirsaProductUrlImage"];
             $products["mirsaProductUrlImage"]=$image;
      }
     array_push($response["Products"], $products);





        }
                  die(json_encode($response));


  }

// echoing JSON response

 else {
// no products found
$response["success"] = 0;
$response["message"] = "No Products";
   die(json_encode($response));
 }
    ?>

我得到了这样的回应

  {
 ProductId: "1",
 ProductCode: "118.023",
 ProductDescription: "NEM OVAL (Transparent)",
 ProductPcsInCartoon: "10",
 ProductWeight: "7.55 - 8.05(KG)",
 ProductVolume: "0.104(m3)",
 ProductCodeBType: "NA",
 ProductCodeCType: "NA",
 ProductUrlImage: [
  "1.png",
  "2.png"
 ]
 },


{
    ProductId: "2",
    ProductCode: "118.024",
    ProductDescription: "NEM OVAL (Opac)",
    ProductPcsInCartoon: "10",
    ProductWeight: "7.55 - 8.05(KG)",
    ProductVolume: "7.55 - 8.05(KG)",
    ProductCodeBType: "NA",
    ProductCodeCType: "NA",
    ProductUrlImage: [
            "1.png",
            "2.png"
          ]

第二个JSON对象不包含这2个图像url,它接受$image[]的旧值,因此我需要重新初始化或清空他的值,以某种方式我需要你们的帮助伙计们,你们永远是我们的支持

共有1个答案

宋唯
2023-03-14

我要试试看。因为您从未真正将$image初始化为数组。你真的打算:

$image[] = array()

成为:

$image = array();

这将导致$Image数组每次通过第一个time循环都被重置。

 类似资料:
  • 问题内容: 我注意到,所有内置约束的中的参数都有一个空值。即 首先,为什么允许它们的值为空?我以为您可以仅对不需要附加验证的约束组合将其留空? 另外,请注意,尽管的值为空,但Hibernate Validator仍可以为每个内置约束找到一个验证器实现类,但是如果我为约束将validatedBy留为空白,则我的自定义验证器将永远不会被使用。这是为什么? 谢谢。 问题答案: 那些内置程序以特定于实现的

  • Ray

    Ray 是一个高性能的分布式执行引擎,开源的人工智能框架,目标之一在于:让开发者可以用一个运行在笔记本电脑上的原型算法,仅需添加数行代码就能轻松转为适合于计算机集群运行的(或单个多核心计算机的)高性能分布式应用。这样的框架需要包含手动优化系统的性能优势,同时又不需要用户关心那些调度、数据传输和硬件错误等问题。 与深度学习框架的关系:Ray 与 TensorFlow、PyTorch 和 MXNet

  • X-Ray 运行定义Zend 引擎 include(), require() and eval() 钩子: 使用方法: // adding a compiler hook:xray\set_compiler_hook(function(string $source, string $filename = null) : string { if ($filename === null) {

  • REX-Ray 是一个 EMC {code} 团队领导的开源项目,为 Docker、Mesos 及其他容器运行环境提供持续的存储访问。其设计旨在囊括通用存储、虚拟化和云平台,提供高级的存储功能。 当前支持的系统: Ubuntu Debian RedHat CentOS CoreOS OSX 运行时 CLI: $ export REXRAY_STORAGEDRIVERS=ec2$ export AW

  • 我们每隔一段时间就会打扫一次房间。 Puppet 的 tidy 资源可以帮助你清理已过期的旧文件,从而减少不必要的磁盘占用。 例如,如果你像 生成报告 一节描述的那样启用了 Puppet 的报告, 就会希望定期清除旧的报告文件。 操作步骤 添加如下代码到你的配置清单: tidy { "/var/lib/puppet/reports": age => "1w", recurse => t

  • 问题内容: 我是nodejs和mongodb中的新手。我从nodejs应用程序中的mongodb中读取大约100000条记录时遇到问题。当我尝试获取100000条记录时,出现此错误: 严重错误:CALL_AND_RETRY_LAST分配失败-内存不足 我搜索谷歌,每个人都说配置最大旧空间大小参数,因为v8引擎大约有1,9Gb堆内存。 我的观点是,我通过eclispe运行我的应用,但我不知道如何配置

  • 射线由一个原点向一个确定的方向发射。它被Raycaster(光线投射)所使用, 以用于辅助raycasting。 光线投射用于在各个物体之间进行拾取(当鼠标经过三维空间中的物体/对象时进行拾取)。 构造函数 Ray( origin : Vector3, direction : Vector3 ) origin - (可选)Ray(射线)的原点,默认值是一个位于(0, 0, 0)的Vector3。

  • 问题内容: 在Java中“清空” a的正确方法是什么,以便无需创建新的方法就可以重用?无论是也似乎收到预期的效果。 问题答案: 打电话怎么样?