How to extract data out of a specific PHP array

后端 未结 3 1827
梦如初夏
梦如初夏 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:35

    First you create an empty array, it will be used to store your result.

    $result = array();
    

    You need to iterate through your initial array, you can use foreach().

    Then, given your parent_category_id simply use an if statement to check whether it's the given id or not.

    If it is, just construct and push your result to your $result array.

    Use any of the sort functions you like

    Use the magic return $result;

    You're done.

提交回复
热议问题