I have a multidimensional array, which I want to search and returns its corresponding key so that I can again use the key and return more information from that corresponding array.
This is what my array looks like
$add_admin_menu_page = array();
$add_admin_menu_page[] = array('Dashboard', 'dashboard.php', 'dashboard');
$add_admin_menu_page[] = array('Posts', 'posts.php', 'posts');
$add_admin_menu_page[] = array('Comments', 'comments.php', 'comments');
$add_admin_menu_page[] = array('Tools', 'tools.php', 'tools');
This is what am doing currently to make it work
<?php
//global $add_admin_menu_page;
$page = "dashboard.php";
$key = array_search($page, $add_admin_menu_page);
var_dump($key);
?>
Above result outputs
bool(false)
Here is an example from array_search by buddel:
function recursive_array_search($needle,$haystack) {
foreach($haystack as $key=>$value) {
$current_key=$key;
if($needle===$value OR (is_array($value) && recursive_array_search($needle,$value) !== false)) {
return $current_key;
}
}
return false;
}