如何在laravel中获取多维数组

时间:2018-07-04 09:04:14

标签: laravel

<StepLabel />

我想将此数组更改为关联数组格式

array(
    'id' => 1,
    'title' =>'BlackBerry Leather Smart Flip Case for BlackBerry PRIV',
    'product_type' => 'Mobile',
    'product_image' => array(
        0 => array(
            'product_id' => 1,
            'image_src'=> 'https://22198_grande.jpg',
            'variant_ids' => 11
        )
    ),
    'product_variant' => array(
        0 => array(
            'product_id' => 1,
            'image_id' => 21,
            'title' => "BlackBerry Leather Smart Flip Case for BlackBerry PRIV/black",
            'price' => 250
        )
    )
);

1 个答案:

答案 0 :(得分:0)

为此使用laravel映射功能

$multiplied = $schoolkids->map(function ($kids) {
$test = $kids;
$temp = collect($kids->toArray());
return $temp->except(['id','class_id','org_id','section_id','parent_id', 'parent_info', 'class_name', 'classes', 'org_detail'])->merge($kids->orgDetail->toArray())->merge($kids->parentInfo->toArray())->merge($kids->classes->toArray());
});

$ multiplied是主要查询,Kids是第一个数组函数,如果要从数组中删除一些除使用函数以外的id