我们可以通过在PHP中返回多个值来实现和回显表吗?
阵列:
$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
)
)
)
)
)
)
功能:
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;
}
并显示表格:
$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>";
我试图返回这些值并转换为数组,但无法列出结果。另外我认为数组的逻辑可能不正确,让函数没有正确显示。 (显示所有日期并使用ASC排序)
此外,我被认为是“约会”,所以当预订2个房间的用户时,我将“date”更改为“date2”。
答案 0 :(得分:0)
如果你得到php错误,在return语句中尝试这样:“解析错误:语法错误,意外','在filename.php行#”
return $date1String."&&".$date2String;