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? Link to comment https://forums.phpfreaks.com/topic/79971-check-for-value-in-multidimensional-associative-array/ 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"); ? Link to comment https://forums.phpfreaks.com/topic/79971-check-for-value-in-multidimensional-associative-array/#findComment-405188 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.