我正在使用codeigniter,是的我已经搜索了互联网,我有in_array()
,但它似乎无效。
这里是我从数据库中获取的数组。
Array ( [0] => stdClass Object ( [FormCIPath] => admin/dashboard/System ) [1] => stdClass Object ( [FormCIPath] => admin/dashboard/Users ) [2] => stdClass Object ( [FormCIPath] => admin/residentials/# ) [3] => stdClass Object ( [FormCIPath] => admin/configurations/# ) [4] => stdClass Object ( [FormCIPath] => admin/configurations/ManageForms ) [5] => stdClass Object ( [FormCIPath] => admin/residentials/Houses ) [6] => stdClass Object ( [FormCIPath] => admin/residentials/Flats ) [7] => stdClass Object ( [FormCIPath] => admin/configurations/ManageTabs ) [8] => stdClass Object ( [FormCIPath] => admin/configurations/SitePreferences ) [9] => stdClass Object ( [FormCIPath] => admin/usersManageUsers/# ) [10] => stdClass Object ( [FormCIPath] => admin/usersManageUsers/CreateUser ) [11] => stdClass Object ( [FormCIPath] => admin/usersManageUsers/ListUsers ) )
我想找出数组中是否存在configurations/ManageForms
,所以我尝试了这样。
$partialURI = $class."/".$method;
if(in_array($partialURI,$result)){
return "True";
}
else{
return "FALSE";
}
但我总是得到假的回报。我已经检查了它返回$partialURI
的变量configurations/ManageForms
。
但我仍然得到FALSE作为回报,你可以看到这个文本存在于上面的数组中?
答案 0 :(得分:2)
由于in_array()
仅适用于flat,因此您可以使用简单的foreach循环:
$partialURI = $class."/".$method;
foreach($result as $r) {
if(stripos($r->FormCIPath, $partialURI) !== false) {
return 'true';
}
}
return 'false';
答案 1 :(得分:1)
试试这个:
$data= new array ();
foreach ($result as $r) {
$data[]=$r;
}
现在,将$result
数组替换为$data
$partialURI = $class."/".$method;
if(in_array($partialURI,$data)){
return "True";
}
else{
return "FALSE";
}