dongtiao0657 2019-07-30 15:16
浏览 61

JSON解码foreach - >只交付1行

my code only delivery 1 row. The first. This JSON contain 3000 rows.

Does anyone know why? Thanks!

if (!empty($_GET["cuit"])){

    $cuit = $_GET["cuit"];
    $directorioDocs = 'data/docs/';
    $data = file_get_contents("data/data.json");
    $proveedores = json_decode($data, true);

    $i = 0;
    foreach ($proveedores as $proveedor) {

        if ($cuit == $proveedor[$i]['cuit']) {
            $proveedorArray = array(
                "cuit" => $proveedor[$i]['cuit'],
            );


        }
        else {$proveedorArray = array("Data" => "Debe ingresar un cuit");
        }
        $i = $i + 1;

    }

    echo json_encode($proveedorArray);
}
else
{
    $proveedorArray = array("Data" => "Debe ingresar un cuit");
    echo json_encode($proveedorArray);

}
  • 写回答

2条回答 默认 最新

  • duanpendan8067 2019-07-30 15:21
    关注
    $proveedorArray = array(
        "cuit" => $proveedor[$i]['cuit'],
    );
    

    Creates a new array each iteration through the loop. You need to append instead:

    // assuming each item in the parent array should be another array
    $proveedorArray[] = array(
        "cuit" => $proveedor[$i]['cuit'],
    );
    

    You'll also have to do the same in your else case inside the loop.

    评论

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失