array (size=9)
0 =>
array (size=2)
'x' => int 1
'y' => int 4
1 =>
array (size=2)
'x' => int 1
'y' => int 5
2 =>
array (size=2)
'x' => int 1
'y' => int 6
3 =>
array (size=2)
'x' => int 1
'y' => int 7
4 =>
array (size=2)
'x' => int 1
'y' => int 8
5 =>
array (size=2)
'x' => int 4
'y' => int 9
6 =>
array (size=2)
'x' => int 5
'y' => int 9
7 =>
array (size=2)
'x' => int 6
'y' => int 9
8 =>
array (size=2)
'x' => int 7
'y' => int 9
The above is an array of x and y coordinates where I have battle ships plotted, I want to search the array and return true when the x,y I send matches the x,y pair of arrays. I can do it if I choose just x on it's own, or y on it's own, but having trouble searching both x and y.
function searcharray($value, $key, $array) {
foreach ($array as $k => $val) {
//echo $val[$key];
if ($val[$key] == $value) {
return TRUE;
//$val[$key];
}
}
return null;
}
$array;
// both these must match
$key='y';
$value=9;
$key2='x';
Varlue2='5';
$result = searcharray($value,$key,$array);
echo $result;