根据值爆炸数组
P粉252423906
P粉252423906 2024-02-21 20:42:42
0
1
311

我有这样构建的数组

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;
    }
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板