Multidimensional array search
Posted: Mon Oct 31, 2011 10:03 am
Hi,
i've been trying to create a function to check x and y coordinates from a mouse click to see whether an object exists. i have a multidimensional array $a, which has arrays with the name of the object, x and y (i.e."red triangle", 100, 100) for multiple objects, potentially hundreds.
What i want to do is search through the multiarray for these x and y coordinates and if any are found return the name (i.e. 'red triangle'. If none return none.
I've managed to create an in_multiarray function which checks for $x and returns true or false. But, not both. Any help would be really appreciated.
public function click($x, $y){
$a = array(array("red triangle", 100, 100),
array("blue circle", 200, 200),
array("orange circle", 50, 50));
i've been trying to create a function to check x and y coordinates from a mouse click to see whether an object exists. i have a multidimensional array $a, which has arrays with the name of the object, x and y (i.e."red triangle", 100, 100) for multiple objects, potentially hundreds.
What i want to do is search through the multiarray for these x and y coordinates and if any are found return the name (i.e. 'red triangle'. If none return none.
I've managed to create an in_multiarray function which checks for $x and returns true or false. But, not both. Any help would be really appreciated.
public function click($x, $y){
$a = array(array("red triangle", 100, 100),
array("blue circle", 200, 200),
array("orange circle", 50, 50));