我有一個數組的數組:讀取參數從一個數組
Array ([0] => Array ([Name] => news/edit)
[1] => Array ([Name] => news/show))
我有以下兩個變量:
$module = 'news';
$action = 'show';
我想看看我的數組包含news/show
或$module/$action
我可以在這裏使用爆炸,但我只能爆炸一個數組。
我有一個數組的數組:讀取參數從一個數組
Array ([0] => Array ([Name] => news/edit)
[1] => Array ([Name] => news/show))
我有以下兩個變量:
$module = 'news';
$action = 'show';
我想看看我的數組包含news/show
或$module/$action
我可以在這裏使用爆炸,但我只能爆炸一個數組。
您是否正在尋找?
$new_array=array_map(function($x){
$y= explode('/',$x['Name']);
return array('module'=>$y[0],'show'=>$y[1]);
},$array);
爲什麼不在檢查之前連接字符串?像這樣:
function doesArrayContainModuleAction($array, $module, $action) {
foreach($array as $subarray) {
if($subarray['Name'] == "$module/$action") return true;
}
return false;
}
工作非常感謝 – xyz
您可以使用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)
將工作謝謝 – xyz
感謝所有的答覆 – xyz