-1

I can check if the value is within the 'Users' but I can't check if the value is within 'Pages' How it will work both Users and Pages?

$mypages = array(
'Pages' => array('pages' => array('add_page', 'edit_page')),
'Users' =>array('view_all_users', 'add_user'));

foreach($mypages as $keys => $key):
    $display = in_array($_GET['page'], $key) ? "block" : "none";
    echo '<ul style="display:'.$display.';"></ul>';
endforeach;
user1157768
  • 53
  • 2
  • 9
  • possible duplicate of [in\_array() and multidimensional array](http://stackoverflow.com/questions/4128323/in-array-and-multidimensional-array) – user4035 Nov 09 '13 at 09:47

2 Answers2

1

It should do:

    if(is_array($key) && array_key_exists('pages', $key)) {
    $display = in_array($_GET['page'], $key['pages']) ? "block" : "none";
} else {
    $display = in_array($_GET['page'], $key) ? "block" : "none";
}
Engineer
  • 5,911
  • 4
  • 31
  • 58
0

Can you try this,

 foreach($mypages as $keys => $key):
   $display ='none';
       if(!is_array($key)){
           $display = in_array($_GET['page'], $key) ? "block" : "none";
        }else{
            $display = in_array($_GET['page'], $key['indexname']) ? "block" : "none";
        }
        echo '<ul style="display:'.$display.';"></ul>';
 endforeach;
Krish R
  • 22,583
  • 7
  • 50
  • 59