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]
所以我在上面写了这个脚本。你能发布一个输入和输出示例吗?你到底想要什么输入和输出?你的服务变量是一个对象,对于合并,使用集合来更新它