I have this array:
$myFruit = 'apple';
$fruits = array(
'0' => array('banana', 'cherry'),
'1' => array('apple', 'pear'),
'2' => array('apple', 'kiwi')
);
I want to know in which array apple is.
So my code is the following and it's working.
foreach($fruits as $key => $fruit) {;
if(in_array($myFruit, $fruit)) {
echo $key;
}
}
My problem is actually apple is in two arrays (1 and 2) and the code echoes 12 whereas it should stop when one result was found.
So it should echo 1 only and stop searching after.
How can I change my code for this ?
Thanks.
breakstatement afterecho $key