0

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.

Chris.C
  • 297
  • 3
  • 17
  • Do you want to [flatten](http://stackoverflow.com/q/1319903/989121) it? – georg Aug 19 '14 at 09:33
  • I would like but I was afraid of the incorrect results will come. – Chris.C Aug 19 '14 at 09:36
  • @learn_PHP using `date2` is not necessary; you can leave it as `date`. It's ok to use the same key name in multiple arrays, the only things is not to use it more than once in [the same] an array. :-) – Emmanuel Okeke Aug 19 '14 at 10:16

1 Answers1

0

try like this in return statement if you get php error: "Parse error: syntax error, unexpected ',' in filename.php on line #"

return $date1String."&&".$date2String;
bhagya
  • 103
  • 1
  • 6