Forum Moderators: coopster
Something like this should work:
function Get_Index($name,$array) {
return [url=http://us3.php.net/manual/en/function.array-search.php]array_search[/url](array('name'=>$name),$array);
}
2)
This returns the numerical key of the first array, so then you would just do this:
$array = $a[Get_Index('kate',$a)];
echo '<pre>';
print_r($array);
echo '</pre>';
Good luck! :)
$a[0]['name'] = 'kate';
$a[0]['lastname'] = 'riemann';
$a[1]['name'] = 'john';
$a[1]['lastname'] = 'smith';
$a[2]['name'] = 'mary';
$a[2]['lastname'] = 'santos';
$c = array_search(array('name'=>'john'),$a);
echo $c;
$c is not returning any value.
what I need is value '1' (so i know $a[1] is the right one).
What should i implement to your original function in order to get the proper key?
function Get_Array($name,$array) {
foreach($array as $person) {
if($person['name'] == $name) {
return $person;
}
}
return FALSE;
}
$a[0]['name'] = 'kate';
$a[0]['lastname'] = 'riemann';
$a[1]['name'] = 'john';
$a[1]['lastname'] = 'smith';
$a[2]['name'] = 'mary';
$a[2]['lastname'] = 'santos';
echo '<pre>';
print_r(Get_Array('john',$a));
echo '</pre>';