I have an array which looks like this
$myArray = Array
(
[Standardbox] => Array
(
[details] => Array
(
[name] => Standardbox
)
[resources] => Array
(
[0] => Array
(
[resourceId] => 1
[resourceName] => Knife
[amount] => 1
[unit] => 2
)
[1] => Array
(
[resourceId] => 2
[resourceName] => Fork
[amount] => 1
[unit] => 2
)
)
)
)
and I want to check if the value of 1 of the key resourceId (knife) is present in the array.
I have found some functions here at stackoverflow but nothing really works for my purposes:
This one looks very promising but I think it does not consider that the array is multidimensional:
function multi_key_in_array($needle, $haystack, $key)
{
foreach ($haystack as $h)
{
if (array_key_exists($key, $h) && $h[$key]==$needle)
{
return true;
}
}
return false;
}
and then calling
if(multi_key_in_array(1, $myArray, "resourceId"))
{
// It is present in the array
}
Any help is highly appreciated!
resourcescould be at deeper levels?resourcesis fixed, correct!