tazo todua tazo todua - 2 months ago 5x
PHP Question

Find ARRAY by to its values

I have a multi-dimensional array like so:

$a = array(
'potatoe'=> array(


'apple'=> array(

I am looking for a way to searching the fruit name (with its values) when I only know weight is
and year is
. How to do that?


You will have to iterate over it using foreach and test every element.

function findFruit($array,$weight, $year){
    foreach($array as $key => $fruit){
        if($fruit['weight'] == $weight && $fruit['year'] == $year ){
            return $key;

then, just use the function:

$theFruit = $a[findFruit($a,55,1992)];