php array index extraction -
i created array dynamic like:
$tmp = array ( array("name" > "rob"), array("name" => "bla"));
now wand search "index" in array (with elemnt) name = "rob"
like : give me index array key "rob", answer should 0, index key "bla" sould 1...
is possible to without or foreach function ? standard php function ?
thanks answer.
$index = array_search($key, array_map(function ($item) { return $item['name']; }, $tmp));
requires php5.3
or can use array_keys()
(works in pre-5.3 too)
$indexs = array_keys($tmp, array('name' => $key));
$indexs
array now, because there can of course more 1 index value array('name' => $key)
within $tmp
Comments
Post a Comment