I have a JSON array like this:
"custom_fields": [
{
"label": "Customer_Info",
"data": "10"
},
{
"label": "Customer_Other",
"data": "50"
}
I am able to access the data and print it like this:
$data = $_POST['custom_fields'];
foreach ($data as $item) {
$line = '';
foreach ($item as $key => $value) {
if ($key == 'data'){
$line .= "$key: $value, ";
}
}
$current .= rtrim($line, ', ')."\n";
}
And then I get an output like:
data: 10
data: 50
Problem is, I want to get only the data value where the label is Customer_Info so that I just have a string with the value 10. How do I do that?
Any help is greatly appreciated before I lose the last few remaining hairs :/
if ($key == 'label' && $value != 'Customer_Info') continue;into innerforeach?datais beforelabel?