I have an array of the following structure:
$some_array = array(
array(
'font' => 'Arial',
'label' => 'Arial'
),
array(
'font' => 'PT+Sans:400',
'label' => 'PT Sans'
)
);
Let’s say that I only know that one item has ‘font’ value of ‘PT+Sans:400’ and I need to retrieve the ‘label’ value of that single item. How can I do it easier than iterating through subarrays?
Since you are already using
foreachyou just want other alternatives then you can consider this solutionsSolution 1
You can try to filter your search using
array_filterOutput
If you need only the label
Output
Solution 2
It you are not interested in return the array and all you want is just the label then you should consider
array_reduceOutput