How to loop through array of multiple arrays in php

前端 未结 2 409
滥情空心
滥情空心 2021-01-28 01:11

I am trying to loop through array of arrays in php. Usually get stalked with complex array sometimes but I need your kind assistance with this.

var_dump($array)

2条回答
  •  再見小時候
    2021-01-28 01:23

    Use a loop to build 2 separate arrays:

    foreach($array['ExpensesList'] as $index => $val){
        $array1[$index] = $array['ExpensesList'][$index][0];
        $array2[$index] = $array['ExpensesList'][$index][1];
    }
    

    Then insert each array into your database individually.

    This will not work if any sub array contains an index at 2, so this is explicitly for the example structure you provided.

提交回复
热议问题