Php 从数组中读取参数

Php 从数组中读取参数,php,arrays,Php,Arrays,我有一个数组: Array ( [0] => Array ( [Name] => news/edit ) [1] => Array ( [Name] => news/show ) ) 我有以下两个变量: $module = 'news'; $action = 'show'; 我想看看我的数组是否包含news/show或$module/$action 我可以在这里使用explode,但我只能分解一个数组。为什么不在检查之前将字符串连接起来?像这样:

我有一个数组:

Array ( [0] => Array ( [Name] => news/edit ) 
        [1] => Array ( [Name] => news/show ) ) 
我有以下两个变量:

$module = 'news';
$action = 'show';
我想看看我的数组是否包含
news/show
$module/$action


我可以在这里使用explode,但我只能分解一个数组。

为什么不在检查之前将字符串连接起来?像这样:

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

你在找这个吗

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

您可以使用数组搜索:

$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)