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);
}
$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.
I tell you that the solution was found when analyzing the json
I did it with this tool->
I'm missing this->
foreach ($proveedores['data'] as $proveedor) {
Also remove the index [0] that was already unnecessary
That was it
Thanks