How to extract data out of a specific PHP array

后端 未结 3 1788
梦如初夏
梦如初夏 2021-01-28 07:02

I have a multi-dimensional array that looks like this: The base array is indexed based on category ids from my catalog.

$cat[category_id]

Ea

3条回答
  •  一生所求
    2021-01-28 07:37

    function returnSortedParents($categories, $target_parent){
    
        $new_list = array();
    
        foreach($categories as $index => $array){
            //FIND ONLY THE ELEMENTS MATCHING THE TARGET PARENT ID 
            if($array['parent_category_id']==$target_parent){ 
                $new_list[$index = $array['sort_order'];
            }
    
        return asort($new_list);  //SORT BASED ON THE VALUES, WHICH IS THE SORTING ORDER
    }
    

提交回复
热议问题