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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.