Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php laravel中的数组添加方法_Php_Arrays_Laravel_Laravel 4_Laravel 5 - Fatal编程技术网

Php laravel中的数组添加方法

Php laravel中的数组添加方法,php,arrays,laravel,laravel-4,laravel-5,Php,Arrays,Laravel,Laravel 4,Laravel 5,我尝试使用array\u add方法在for循环中将新元素添加到数组中 public function getNotArray() { // looping over $service Object for($x = 0; $x < count($service); $x++) { $firstService[$x] = $service[$x]->first_date_for_service; while (Carbon::now()

我尝试使用
array\u add
方法在for循环中将新元素添加到数组中

public function getNotArray() {
    // looping over $service Object
    for($x = 0; $x < count($service); $x++) {
        $firstService[$x] = $service[$x]->first_date_for_service;
        while (Carbon::now() > $firstService[$x]) {
            $firstService[$x]->addMinutes($service[$x]->notification_period);
            if($firstService[$x] < Carbon::now() && $firstService[$x] > $service[$x]->serviceHistory->where('status','done')->max('created_at')) {
                $arr[] = array_add($service[$x], 'notificationDate', date($firstService[$x]));
            }
        }
    }
    return  $arr;
}
公共函数getNotArray(){
//在$service对象上循环
对于($x=0;$x服务的第一个日期;
而(Carbon::now()>$firstService[$x]){
$firstService[$x]->addMinutes($service[$x]->通知期);
如果($firstService[$x]$service[$x]->serviceHistory->where('status','done')->max('created_at')){
$arr[]=array_add($service[$x],'notificationDate',date($firstService[$x]);
}
}
}
返回$arr;
}
上面的脚本运行良好,但在循环
$arr

我需要根据
$firstService[$x]
在每个循环中携带的值获取
notificationDate

有什么建议吗,谢谢试试这个

 public function getNotArray() {
  // looping over $service Object
  for($x = 0; $x < count($service); $x++) {

     $firstService[$x] = $service[$x]->first_date_for_service;

     while (Carbon::now() > $firstService[$x]) {

       $firstService[$x]->addMinutes($service[$x]->notification_period);

       if($firstService[$x] < Carbon::now() && $firstService[$x] > $service[$x]->serviceHistory->where('status','done')->max('created_at')) {

          $service[$x] = array_add($service[$x], 'notificationDate', date($firstService[$x]));

       }
     }
   }
   return  $service;
 }
公共函数getNotArray(){
//在$service对象上循环
对于($x=0;$x服务的第一个日期;
而(Carbon::now()>$firstService[$x]){
$firstService[$x]->addMinutes($service[$x]->通知期);
如果($firstService[$x]$service[$x]->serviceHistory->where('status','done')->max('created_at')){
$service[$x]=array_add($service[$x],'notificationDate',date($firstService[$x]);
}
}
}
返回$service;
}

所以我假设你想让它变为变量?没有
$firstService[$x]
在每个循环中都有不同的值我在另一个脚本中尝试过,但我需要
$service[$x]
$firstService[$x]
所以我在上面写了这个脚本。你能发布一个输入和输出示例吗?你到底想要什么输入和输出?你的服务变量是一个对象,对于合并,使用集合来更新它