I'm having trouble accessing a specific value of a variable that returns a JSON in PHP.
My code is as follows:
//Llama el SP
$sql="CALL tramites_G(".$valuesInsert.")";
$resultado = mysqli_query($database,$sql);
if (!$resultado) {
die('error');
} else {
$jsondata["data"]["tramites"] = array();
while($row = $resultado->fetch_array(MYSQLI_ASSOC)){
$jsondata["data"]["tramites"][0] = $row;
}
$code = json_encode($jsondata);
}
$var = json_decode($code,true);
When doing echo in $jsondata
I get the following:
Array ( [data] => Array ( [tramites] => Array ( [0] => Array ( [vtr_id] => 122 ) ) ) )
When doing echo in $code
I get the following:
{"data":{"tramites":[{"vtr_id":"122"}]}}
I need to access the pure value of vtr_id
to assign it to a variable and continue with a series of validations.
I already try to access with $code[0]
but it does not return any value to me. Also with $id= $var->vtr_id;
but still not working.