i got this array:
array = array ("name" = $name, "email" = $email),array ("name" = $name, "email" = $email),array ("name" = $name, "email" = $email),.....
is there any function that will allow me to extract all "name" into an array?
multi dimensional array
Moderator: General Moderators
Re: multi dimensional array
Code: Select all
function getNames($array) {
$names = array();
foreach ($array as $k => $data) {
if (is_array($data) && isset($data['name'])) {
$names[] = $data['name'];
}
}
return $names;
}
Re: multi dimensional array
anyway u can do this w/o loop?(the whole reason i asked)
Re: multi dimensional array
I don't think you can. Are you worried about performance?
Re: multi dimensional array
yh cos i already have the loop which makes that array in the first place but i dont want to run my code in there
Re: multi dimensional array
You can call the function I wrote from anyplace, so you wouldn't have to.jazz090 wrote:but i dont want to run my code in there