Can we implement and echo the table by returning multiple values in PHP?
Array:
$arrayBooking = array(
"a01"=>array(
"Amy"=>array(
"booking1"=>array(
"231"=>array(
"date"=>"21/08/2014",
"period"=>array(
"from"=>1,
"to"=>3
)
)
)
)
),
"a02"=>array(
"Peter"=>array(
"booking1"=>array(
"231"=>array(
"date"=>"22/08/2014",
"period"=>array(
"from"=>2,
"to"=>3
)
)
),
"booking2"=>array(
"231"=>array(
"date2"=>"24/08/2014",
"period"=>array(
"from"=>2,
"to"=>5
)
)
)
)
)
)
And the function:
function bookingDate($arrayBooking, $userID){
$date1String="";
$date2String="";
foreach($arrayBooking as $key => $value){
if($key==$userID){
foreach($value as $id => $val){
foreach($val as $booking => $array){
foreach($array as $room => $detail){
//$reverse = array_reverse($array, true);
foreach($detail as $time => $date){
if($time=="date"){
$date1String = $date;
}
if($time=="date2"){
$date2String = $date;
}
}
}
}
}
}
return $date1String, $date2String;
}
And shows table:
$BookingTable = "<table border=1>";
foreach($arrayBooking as $key => $value){
$BookingTable .= "<tr>";
$BookingTable .= "<td align=center>" . bookingDate($arrayBooking, $key) . "</td>";
$BookingTable .= "<tr>";
}
$BookingTable = "<table border=1>";
I have tried to return those values and convert to an array but it could not list the result. Also I think the logic of the array may be incorrect and let the function did not show correctly. (show all dates and sorting with ASC)
Furthermore, I was considered "date" so I change "date" to "date2" while the user who booked 2 rooms.