如何合并此数组?Php

如何合并此数组?Php,php,arrays,laravel,sorting,for-loop,Php,Arrays,Laravel,Sorting,For Loop,我已经尝试合并这个数组好几个小时了,但是我没有得到它,我有两个数组,一个叫做“period”,另一个叫做“time” 时期 "periodo":{"periodo":[["2017-06-22","2017-06-23","2017-06-24"],["2017-06-22","2017-06-23","2017-06-24"]]} 蒂恩波 "tiempo":[{"inicio":"2:00 am","fin":"3:00 am"},{"inicio":"3:00 am","fin":"4:0

我已经尝试合并这个数组好几个小时了,但是我没有得到它,我有两个数组,一个叫做“period”,另一个叫做“time”

时期

"periodo":{"periodo":[["2017-06-22","2017-06-23","2017-06-24"],["2017-06-22","2017-06-23","2017-06-24"]]}
蒂恩波

"tiempo":[{"inicio":"2:00 am","fin":"3:00 am"},{"inicio":"3:00 am","fin":"4:00 am"},{"inicio":"4:00 am","fin":"5:00 am"},{"inicio":"5:00 am","fin":"6:00 am"},{"inicio":"6:00 am","fin":"7:00 am"},{"inicio":"2:00 am","fin":"3:00 am"},{"inicio":"3:00 am","fin":"4:00 am"},{"inicio":"4:00 am","fin":"5:00 am"},{"inicio":"5:00 am","fin":"6:00 am"},{"inicio":"6:00 am","fin":"7:00 am"}]
这是我的密码

public function testArray(Request $request)
               {
                 if ($request!="" && $request->idUser!="") 
                 {
                  $timeslot= new Timeslot;
                  $idUser=$request->idUser;
                  $fecha1=$request->fecha1;
                  $fecha2=$request->fecha2;
                  $tiempo1=$request->desde;
                  $tiempo2=$request->hasta;

                  $slotD=$request->slotH;
                  $i=0;
                  $k=0;
                  $j=0; 
                  $l=0;
                  $m=0;
                  foreach ($fecha1 as $key => $value) {
                     $date1[$k]=date('Y-m-d', strtotime($value));
                   $k++;
                  }
                  foreach ($fecha2 as $key => $value) {
                    $date2[$i]=date('Y-m-d', strtotime($value));
                   $i++;
                  }

                  foreach ($tiempo1 as $key => $value) {
                     $value=strtotime($value);

                     $time1[$l]=$value;
                   $l++;
                  }
                   foreach ($tiempo2 as $key => $value) {
                      $value=strtotime($value);
                     $time2[$m]=$value;
                   $m++;
                  }


                  foreach ($slotD as $key => $value) {
                     $value=str_replace("minutos","minutes",$value);
                     $value=str_replace("horas","hours",$value);
                     $value=str_replace("hora","hours",$value);
                     $slot[$j]=$value;
                    $j++;
                  }

                  $array=array("horaInicio"=>$time1,"Horafin"=>$time2);

                  for($l1=0;$l1<count($date1);$l1++)
                  {
                   //$datePeriod["periodo"]=$timeslot->returnDates($date1[$l],$date2[$l]);
                   $datePeriod["periodo"][$l1]=$timeslot->createDateRangeArray($date1[$l1],$date2[$l1]);

                   //echo $datePeriod[$l]->format('Y-m-d');
                     }

                  $n=0;
                  for($i2=0;$i2<count($time1);$i2++)
                  {
                   while ($time1[$i2] < $time2[$i2]) {
                     //echo date('g:i:s', $time) . " - ";
                     $tiempo[$n]["inicio"]=date('g:i a', $time1[$i2]);
                     $time1[$i2] = strtotime('+'.$slot[$i2], $time1[$i2]);
                     //echo date('g:i a', $time) . "<br>";
                     $tiempo[$n]["fin"]=date('g:i a', $time1[$i2]);

                     $n++;
                        }
                  }



                 foreach ($datePeriod as $key => $value)
               { 
                   $id=rand();

                 foreach ($tiempo as $value2) {
                   /*
                   $timeslot= new Timeslot;
                   $timeslot->user_id=$idUser;
                   $timeslot->slot_date=$value[$key];
                   $timeslot->inicio=$value2['inicio'];
                   $timeslot->fin=$value2['fin'];
                   $timeslot->slot_id=$id;
                   $timeslot->slot_status=0;
                   $timeslot->save();*/

                   //$response["fecha"][]=$value["periodo"][$key];
                   $response["fecha"][]=$value2['inicio'];
                   $response["fecha"][]=$value2['fin'];
                   $response["fecha"][]=$id;

                     }

                 }

                 }else{
                   $response["success"]=false;
                 }



                // print_r($tiempo); 
                   //print_r($datePeriod);
                 return array("periodo"=>$dates,"tiempo"=>$tiempo);
               // return $response;
               }

但是,我找不到访问数组内部值的方法,因为每个值都不同,我如何解决这个问题?

这些不是数组,而是JSON字符串。将它们解析为数组,然后合并它们。一旦使用
JSON\u encode()
再次将输出合并为JSON。嗨,jay,我尝试使用函数array\u merge来实现这一点,但是顺序是唯一失败的事情,它们不是数组,而是JSON字符串。将它们解析为数组,然后合并它们。使用
JSON\u encode()
再次将输出合并为JSON。嗨,jay,我尝试使用函数array\u merge执行此操作,但顺序是唯一失败的地方
               function createDateRangeArray($strDateFrom,$strDateTo)
           {
               // takes two dates formatted as YYYY-MM-DD and creates an
               // inclusive array of the dates between the from and to dates.

               // could test validity of dates here but I'm already doing
               // that in the main script

               $aryRange=array();

               $iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2),     substr($strDateFrom,8,2),substr($strDateFrom,0,4));
               $iDateTo=mktime(1,0,0,substr($strDateTo,5,2),     substr($strDateTo,8,2),substr($strDateTo,0,4));

               if ($iDateTo>=$iDateFrom)
               {
                   array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry
                   while ($iDateFrom<$iDateTo)
                   {
                       $iDateFrom+=86400; // add 24 hours
                       array_push($aryRange,date('Y-m-d',$iDateFrom));
                   }
               }
               return $aryRange;
           }
                foreach ($dates as $key => $value)
               { 
                 $id=rand();


                 foreach ($tiempo as $value2) {
                  /* $timeslot= new Timeslot;
                   $timeslot->user_id=$idUser;
                   $timeslot->slot_date=$value[$key];
                   $timeslot->inicio=$value2['inicio'];
                   $timeslot->fin=$value2['fin'];
                   $timeslot->slot_id=$id;
                   $timeslot->slot_status=0;
                   $timeslot->save();
                   */
                   $response["fecha"][]=$value[$key];
                   $response["fecha"][]=$value2['inicio'];
                   $response["fecha"][]=$value2['fin'];
                   $response["fecha"][]=$id;

                 }

               }