Page 1 of 1

Multidimensional array search

Posted: Mon Oct 31, 2011 10:03 am
by sb439
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));

Re: Multidimensional array search

Posted: Mon Oct 31, 2011 10:14 am
by dsnraju
This Problem is solved by JavaScript "onMouseOver" Event. They can return the mouse point position x,y coordinates.

Re: Multidimensional array search

Posted: Mon Oct 31, 2011 11:10 am
by sb439
Hi,

thanks for that. However, i already have the x and y coordinates from (AS3 e:mouse event (e.target.parent.mouseX and e.target.parent.mouseY).

I'm wanting to check to see if they are in my array and return the object name associated to them i.e. 'orange circle' at x 100 and y 200 or no object found

I need the code in php, as i'm using this as an amf function (backend) for a ActionScript 3 (front end).

Regards SB439