0
当我尝试使用in_array功能在PHP第二次对相同的数组变量i得到以下错误说:变量不是数组PHP
in_array()预计参数2为阵列,串给定的在
当我包装在条件is_array的功能,则返回false,我已经打印使用的print_r及其表示阵列结构的变量,这里的代码:
$chosenCour = array();
$chosenServ = array();
foreach ($preferences as $preference) {
if(!in_array($preference['courier'],$chosenCour)){
$chosenCour[] = $preference['courier'];
}
if(!in_array($preference['courier_service'],$chosenServ)){
$chosenServ[]= $preference['courier_service'];
}
}
foreach ($couriers as $courier) {
$courCond = false;
if(is_array($chosenCour)){
if(in_array($courier['courier_id'],$chosenCour)){
$courCond = true;
}
}
}
**定义:**'in_array(混合$针,数组$草垛[,布尔$严格= FALSE])' - 这意味着,你定义你想搜索首先,然后设置所需的数组,而不是相反的方式,就像你做'in_array($ preference ['courier'],$ chosenCour)' – Peon
@DainisAbols我第一次使用in_array时没有问题,但第二次,我想要重用的变量即使在is_array函数中也不会被识别为数组 –