Searching a PHP array
Posted: Wed Dec 10, 2008 4:39 am
Hi
I've been looking for a solution to this problem for a while, and now my head's spinning as I can't find anything that looks right!
I have an array similar to below...
Now, I'm trying to search the array with a name (values of first and last names are returned from a database query), and return the email address. Most of the solutions I've found so far only look for one value, but I need to check for 2 (ie both first and last names in case of duplicates) - but then I also need to return the email address if a match is found; and I've not found any ways of doing that yet. It's quite possible that there is a solution somewhere on the PHP.net website, but I'm a bit lost with the different array functions.
Anyone got any pointers, please?
I've been looking for a solution to this problem for a while, and now my head's spinning as I can't find anything that looks right!
I have an array similar to below...
Code: Select all
$namesArray = array(
array("firstname"=>"John", "lastname"=>"Smith", "email"=>"johnsmith@gmail.com"),
array("firstname"=>"Arthur", "lastname"=>"Sixpence", "email"=>"arthur@yahoo.co.uk"),
array("firstname"=>"John", "lastname"=>"Green", "email"=>"john.green@yahoo.com"),
array("firstname"=>"Dave", "lastname"=>"Smith", "email"=>"d.smith@gmail.com")
)Anyone got any pointers, please?