I am trying to print the value of a field of an array or json table, specifically from the providers table, the services field, for example, like this: ["3", "3", "Marketing", "Graphic Design"]
When printing it I use MVC and the controller sends me the data correctly.
$providers = ProvidersController::getProviders($item, $value);
foreach ($providers as $key => $value):
echo $value["name"];
echo "<br>";
}
endforeach;
However, to print the services field, I can only print it when I assign the manual value to a specific record, such as here where it only prints 4:
$services = json_decode($providers[4]["services"], true);
foreach ($services as $key => $value) {
echo $value."<br>";
}
But of course I need to print either all the records or sometimes a specific one, I have tried to assign the value with a for $i for example but it gives an error. What other option could I try?
$providers = ProvidersController::getProviders($item, $value);
foreach ($providers as $key => $value):
echo $value["name"];
echo "<br>";
for($i = 0; $i<=count($providers); $i++){
$services = json_decode($providers[$i]["services"], true);
foreach ($services as $key => $value) { //Error
echo $value."<br>";
}
}
}
endforeach;