我有这行代码:
$roomservicesids = array_map(function($v){ return $v['serviceID'];}, $roomsservices);
它在我有 PHP > 5.3 的服务器上运行良好 在另一台服务器上,我有 PHP < 5.3,它不起作用。我正在尝试像这样重写它:
$roomservicesids = create_function('$v', 'return $v["serviceID"];,$roomsservices');
foreach ($services as $key1=>$value){
if(in_array($value['serviceID'], $roomservicesids)){ //error is in this line
echo "<input type='checkbox' name='services[]' id= '".$value['serviceID']."' value='" .$value['serviceID'] ."' checked = 'checked' class='zcheckbox' />";
}else{
echo "<input type='checkbox' name='services[]' id= '".$value['serviceID']."' value='" .$value['serviceID'] ."' class='zcheckbox' />";
}
echo "<label>" .$value['serviceName']. "</label>";
}
但我收到一条错误消息:
Message: in_array() [function.in-array]: Wrong datatype for second argument
Line Number: 104
任何帮助将不胜感激。