I'm trying to build a routine which outputs nav menu depending on user status. It needs to be fed a nested array variable (company => role) which looks like:
array(2) {
["Company 1"]=>
array(2) {
[0]=>
string(3) "dir"
[1]=>
string(5) "manag"
}
["company 2"]=>
string(3) "dir"
}
It is assumed, that a user can have multiple roles.
Now my routine (simplified version, just to show the logic isnt working):
function get_menu_1 ($status) {
foreach ($status as $company => $position) {
$a = is_array($company); //THIS ALWAYS RETURNS FALSE this is for debugging
echo "<br>this element is array = $a<br>"; //this is for debugging
if (true == is_array($company)) { // THIS ALWAYS RETURNS FALSE this user in this company has multiple roles
foreach ($company as $subcompany => $subposition) {
echo "<br>$subposition<br>";
}
} else { //its not an array, user has one role in the company
echo "<br>$position<br>";
}
}
}
The output is:
Notice: Array to string conversion in /sata2/home/users/xreact/www/cert.xreact.org/functions.php on line 393
Array
this element is array =
dir
array(2) { ["Company 1"]=> array(2) { [0]=> string(3) "dir" [1]=> string(5) "manag" } ["Company 2"]=> string(3) "dir" }
For some reason is_array()
fails to check whether the variable is array.