I have a problem concerning my script which allows me to take keys and values of an array ($array) and to add them to an existing array ($arraywithfourwords).
The problem I've encountered is that when I loop over $array, the loop does not break when I expect it to. In the case below, it should break when the value "A" is encountered.
For information, $arraywithfourwords is defined from the beginning, and $array is the array taken at random and to which I attempt to "match" the keys and values of this first array.
$arraywithfourwords before script :
[Aero] => D
[Blue] => V
[Almond] => Q
[Amazon] => X
$array:
[Aero] => D
[Blue] => V
[Almond] => Q
[Amazon] => X
[Android] => A //STOP BREAK THE LOOP
[Cherry] => J //Not continue
[Citrine] => P //Not continue
[Dark] => M //Not continue
[Celeste] => E //Not continue
$fourthKey = [Amazon]
Script:
$passed = false;
foreach($array as $key => $value){
if ($passed && $value != 'A' && $value != 'P')
{
$passed2 = 'valid';
$arraywithfourwords[$key] = $value;
}
if ($key == $fourthKey && $value != 'A' && $value != 'P')
{
$passed = true;
}
if ($passed2 == 'valid')
{
break;
}
}
print_r($arraywithfourwords);
$arraywithfourwords after script:
[Aero] => D
[Blue] => V
[Almond] => Q
[Amazon] => X
[Cherry] => J //My problem
$arraywithfourwords after script that I search:
[Aero] => D
[Blue] => V
[Almond] => Q
[Amazon] => X