如何将单个对象附加到数组的对象中?

时间:2017-11-05 06:54:01

标签: php laravel-5

我在laravel 5.4控制器中使用$date_wise=DB::select('') $date_wise返回:

  array:8 [▼
  0 => {#740 ▼
    +"justManifest": 230045
    +"manifes_no": "230045/6/2017"
    +"total_truck": "6"
    +"total_truck_entered": 3
    +"remaining_trucks": 3.0
    +"cargo_name": "Fruit and vegetables"
    +"truck_no": "2001"
    +"truck_type": "NBJH"
    +"created_by": "truck"
    +"driver_card": "567767878"
    +"truckentry_datetime": "2017-10-25 09:34:36"
  }
  1 => {#742 ▼
    +"justManifest": 890
    +"manifes_no": "890/3/2017"
    +"total_truck": "3"
    +"total_truck_entered": 3
    +"remaining_trucks": 0.0
    +"cargo_name": "Baby Texi, Three Wheeler, Scooter, Motor Cycle & Motor Car Tyre & Tube(Size: Below-700)"
    +"truck_no": "7654"
    +"truck_type": "WB"
    +"created_by": "truck"
    +"driver_card": "8765"
    +"truckentry_datetime": "2017-10-25 09:34:37"
  }
  2 => {#744 ▼
    +"justManifest": 890
    +"manifes_no": "890/3/2017"
    +"total_truck": "3"
    +"total_truck_entered": 3
    +"remaining_trucks": 0.0
    +"cargo_name": "Baby Texi, Three Wheeler, Scooter, Motor Cycle & Motor Car Tyre & Tube(Size: Below-700)"
    +"truck_no": "78631"
    +"truck_type": "WB"
    +"created_by": "truck"
    +"driver_card": "6543"
    +"truckentry_datetime": "2017-10-25 09:34:40"
  }
  3 => {#743 ▼
    +"justManifest": 230045
    +"manifes_no": "230045/6/2017"
    +"total_truck": "6"
    +"total_truck_entered": 3
    +"remaining_trucks": 3.0
    +"cargo_name": "Fruit and vegetables"
    +"truck_no": "3001"
    +"truck_type": "NBJK"
    +"created_by": "truck"
    +"driver_card": "4567890"
    +"truckentry_datetime": "2017-10-25 09:34:48"
  }
  4 => {#747 ▼
    +"justManifest": 45777
    +"manifes_no": "45777/A/2017"
    +"total_truck": "A"
    +"total_truck_entered": 1
    +"remaining_trucks": -1.0
    +"cargo_name": "Fruit and vegetables"
    +"truck_no": "1009"
    +"truck_type": "BNDE"
    +"created_by": "truck"
    +"driver_card": "4567890"
    +"truckentry_datetime": "2017-10-25 09:35:52"
  }
  5 => {#748 ▼
    +"justManifest": 230045
    +"manifes_no": "230045/6/2017"
    +"total_truck": "6"
    +"total_truck_entered": 3
    +"remaining_trucks": 3.0
    +"cargo_name": "Fruit and vegetables"
    +"truck_no": "4001"
    +"truck_type": "BHUI"
    +"created_by": "truck"
    +"driver_card": "877788"
    +"truckentry_datetime": "2017-10-25 09:36:44"
  }
  6 => {#746 ▼
    +"justManifest": 890
    +"manifes_no": "890/3/2017"
    +"total_truck": "3"
    +"total_truck_entered": 3
    +"remaining_trucks": 0.0
    +"cargo_name": "Baby Texi, Three Wheeler, Scooter, Motor Cycle & Motor Car Tyre & Tube(Size: Below-700)"
    +"truck_no": "8743"
    +"truck_type": "WB"
    +"created_by": "truck"
    +"driver_card": "8776"
    +"truckentry_datetime": "2017-10-25 12:42:28"
  }
  7 => {#749 ▼
    +"justManifest": 2510
    +"manifes_no": "2510/A/2017"
    +"total_truck": "A"
    +"total_truck_entered": 1
    +"remaining_trucks": -1.0
    +"cargo_name": "RAW COTTON"
    +"truck_no": "123"
    +"truck_type": "WB"
    +"created_by": "truck"
    +"driver_card": "987654321"
    +"truckentry_datetime": "2017-10-25 16:33:05"
  }
]

如何将索引编号3推到索引编号1? 我想连续justmanifest _没有230045。所有相同的justmanifest不会是一个序列号。 我怎么能在PHP? 我试过了: 我使用foreach循环对象然后在新对象中获取唯一。当没有3来自同一justmanifest没有230045我试图将其追加到没有。 0.但找不到附加对象特定索引的任何方法。

预期产出:

    array:8 [▼
  0 => {#740 ▼
    +"justManifest": 230045
    +"manifes_no": "230045/6/2017"
    +"total_truck": "6"
    +"total_truck_entered": 3
    +"remaining_trucks": 3.0
    +"cargo_name": "Fruit and vegetables"
    +"truck_no": "2001"
    +"truck_type": "NBJH"
    +"created_by": "truck"
    +"driver_card": "567767878"
    +"truckentry_datetime": "2017-10-25 09:34:36"
  }
  1 => {#743 ▼
    +"justManifest": 230045
    +"manifes_no": "230045/6/2017"
    +"total_truck": "6"
    +"total_truck_entered": 3
    +"remaining_trucks": 3.0
    +"cargo_name": "Fruit and vegetables"
    +"truck_no": "3001"
    +"truck_type": "NBJK"
    +"created_by": "truck"
    +"driver_card": "4567890"
    +"truckentry_datetime": "2017-10-25 09:34:48"
  }

  2 => {#742 ▼
    +"justManifest": 890
    +"manifes_no": "890/3/2017"
    +"total_truck": "3"
    +"total_truck_entered": 3
    +"remaining_trucks": 0.0
    +"cargo_name": "Baby Texi, Three Wheeler, Scooter, Motor Cycle & Motor Car Tyre & Tube(Size: Below-700)"
    +"truck_no": "7654"
    +"truck_type": "WB"
    +"created_by": "truck"
    +"driver_card": "8765"
    +"truckentry_datetime": "2017-10-25 09:34:37"
  }

0 个答案:

没有答案