根據數值爆炸數組
P粉252423906
P粉252423906 2024-02-21 20:42:42
0
1
309

我有這樣建構的陣列

array (size=2)
  0 => 
    array (size=12)
      'id_objects' => string '2876' (length=4)
      'room_val' => string '1882840,1882841,1882842' (length=23)
      'date_from' => string '2022-06-22' (length=10)
      'date_to' => string '2022-06-22' (length=10)
  1 => 
    array (size=12)
      'id_objects' => string '2876' (length=4)
      'room_val' => string '3198723,3198724,3198726' (length=23)
      'date_from' => string '2022-06-22' (length=10)
      'date_to' => string '2022-06-22' (length=10)

我需要實現的是,爆炸'room_val'但保持其餘資料相同,它需要看起來像這樣

array (size=2)
  0 => 
    array (size=12)
      'id_objects' => string '2876' (length=4)
      'room_val' => string '1882840' (length=23)
      'date_from' => string '2022-06-22' (length=10)
      'date_to' => string '2022-06-22' (length=10)
1 => 
    array (size=12)
      'id_objects' => string '2876' (length=4)
      'room_val' => string '1882841' (length=23)
      'date_from' => string '2022-06-22' (length=10)
      'date_to' => string '2022-06-22' (length=10)
 
..... rest of array

可能嗎?

P粉252423906
P粉252423906

全部回覆(1)
P粉436688931

您需要解析數組數組並建立一個與您要查找的內容相符的新數組。

類似:

$myNewArray = [];
foreach ($arrays as $array) {
    $room_vals = $array['room_val'];
    foreach ($room_vals as $room_val) {
        $newSubArray = $array;
        $newSubArray['room_val'] = $room_val;
        $myNewArray[] = $newSubArray;
    }
}
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板