{
"success": true,
"response": [
{
"idseparacion": "1",
"idcalidad": "21",
"peso": "500",
"cajas": "50",
"restante": 100
},
{
"idseparacion": "2",
"idcalidad": "21",
"peso": "1000",
"cajas": "50",
"restante": 0
},
],
}
I have my json as it is in the format the problem is that I want to delete the elements that have restante 0
use:
unset($data[$key]);
which eliminates the data to me well, the problem is that I add them in quotes the number of object remaining like this:
"response": [
"1":{ ///<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
"idseparacion": "1",
"idcalidad": "21",
"peso": "500",
"cajas": "50",
"restante": 100
}
],
Why is this happening?
That another way I recommend to remove objects
PHP Code
foreach($data as $key => $value){
$cajasSeparacion = $this->getCajasCalidad($value['idseparacion']);
$cajasTarimadas = $this->getTarimasCajas($value['idseparacion']);
$valorRestante = $cajasSeparacion->cajas - $cajasTarimadas->tarimadas;
$data[$key]['restante'] = $valorRestante;
if($valorRestante <= 0){
unset($data[$key]);
}
}