Fetch values from an array using nested foreach loop

后端 未结 1 1980
挽巷
挽巷 2021-01-25 08:28

I have a long array from which I wish to fetch all the values and store it in a separate variable, and store each value in database.

The array that I have is:

         


        
1条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-25 08:54

    If you now how deep your array is you can just simply add other foreach-loops within your main loop.

    if (!empty($array)) 
    {
        foreach ($array['categories'] as $category) 
            {
                echo $category['category_id'];
                echo "
    "; if(isset($category['categories'])){ foreach($category['categories'] as $category2) { echo $category2['category_id']; echo "
    "; if (isset($category2['categories'])){ foreach($category2['categories'] as $category3) { echo $category3['category_id']; echo "
    "; ... } } }} } }

    0 讨论(0)
提交回复
热议问题