I am trying to display a select box with multiple select
I have two array one for option value $course another for $selected_course
here is my code kindly review it and inform me where I have done my mistake.
$course =stdClass Object
(
[Id] => 4
[name] => EME
[desc] =>
[details] =>
[created_by] => 0
[created_on] => 2016-01-01 23:47:15
[ip] =>
[status] => 0
)
$selected_course= Array
(
[0] => 4
[1] => 2
)
Now here is my code:
<?php
$i=0;
foreach ($courses as $course) {
$select_Course=explode(',',$center->course) ;
?>
<option <?php echo (isset($select_Course[$i]) || $select_Course[$i]==$course->Id)?'selected':false;?> value="<?=$course->Id;?>"><?=$course->name;?></option>
<?php
$i++;
} ?>
Its not selecting anyone of them why ?? I have tried in_array , array_search but failed
$select_Course[$i]and$course->Id.<option <?php echo (array_search($course->Id, $select_Course))?'selected':false;?>but its also not giving me the proper result$coursesarray contains all$courseobject, right?