Bramme Posted December 3, 2007 Share Posted December 3, 2007 I've got a multidimensional associative array that looks like this: Array ( [cont] => Array ( [filename] => /var/www/vhosts/bramme.net/subdomains/dev/httpdocs/admin/modules/content.php [name] => 2-Content [subnav] => Add, Edit, Delete pages [dependent] => 3-Navigation ) [dashboard] => Array ( [filename] => /var/www/vhosts/bramme.net/subdomains/dev/httpdocs/admin/modules/dashboard.php [name] => 1-Dashboard [subnav] => [dependent] => ) [nav] => Array ( [filename] => /var/www/vhosts/bramme.net/subdomains/dev/httpdocs/admin/modules/navigation.php [name] => 3-Navigation [subnav] => Edit [dependent] => 2-Content ) ) A function reads a set directory and builds that array, as you can see, some files need another, indicated with the dependent file's name. Now I need to check for each array key (cont, dashboard, nav) if their dependent value (if any) matches any of the name values, thus being sure the dependent file is existent too. Instead of building a new piece of code that loops through my directory again, I thought I could just do it with !in_array, like this foreach($this->modules as $module) { if(!empty($module['dependent'])) { $dep = $module['dependent']; if(!in_array($dep, $this->modules[]['name'])) { die("Dependent file not present"); } } } but it's clearly not working. Anyone suggestions on how to do this? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted December 3, 2007 Share Posted December 3, 2007 How about $is_found = false; foreach($this->modules as $module) { if($module['name'] == $dep) { $is_found = true; break; } } if(!$is_found) die("Dependent file not present"); ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.