I have this line of code :
$roomservicesids = array_map(function($v){ return $v['serviceID'];}, $roomsservices);
It works great on a server where I have PHP > 5.3 On another server, where I have PHP < 5.3, it doesn't work. I am trying to rewrite it like this:
$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>";
}
But I get an error that say:
Message: in_array() [function.in-array]: Wrong datatype for second argument
Line Number: 104
Any help will be deeply appreciated.
$roomservicesids = array_map(function($v){ return $v['serviceID'];}, $roomsservices);
This is a compact way of getting the serviceID
of each array element. You can do it with an explicit loop like so:
$roomservicesids = array();
foreach ($roomsservices as $service) {
$roomservicesids[] = $service['serviceID'];
}