Jump to content

check for value in multidimensional associative array.


Bramme

Recommended Posts

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.