1

I have an array of arrays:

Array ( [0] => Array ( [Name] => news/edit ) 
        [1] => Array ( [Name] => news/show ) ) 

I have the following two variables:

$module = 'news';
$action = 'show';

I want to see if my array contains news/show or $module/$action

I can use explode here, but I can only explode one array.

0

3 Answers 3

2

You can use array_search:

$array = array(array("Name" => "news/edit" ), array("Name" => "news/show"));
$module = 'news';
$action = 'show';
var_dump(array_search(array("Name" => "$module/$action"), $array));
// int(1)
Sign up to request clarification or add additional context in comments.

Comments

1

Why don't you just concatenate the strings before checking? Like this:

function doesArrayContainModuleAction($array, $module, $action) {
    foreach($array as $subarray) {
        if($subarray['Name'] == "$module/$action") return true;
    }
    return false;
}

Comments

0

Are you searching for this?

$new_array=array_map(function($x){
     $y= explode('/',$x['Name']);
     return array('module'=>$y[0],'show'=>$y[1]);
},$array);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.