How to “flatten” a multi-dimensional array to simple one in PHP?

前端 未结 23 2115
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 01:03

It\'s probably beginner question but I\'m going through documentation for longer time already and I can\'t find any solution. I thought I could use implode for each dimensio

23条回答
  •  孤独总比滥情好
    2020-11-22 01:34

    This is a one line, SUPER easy to use:

    $result = array();
    array_walk_recursive($original_array,function($v) use (&$result){ $result[] = $v; });
    

    It is very easy to understand, inside the anonymous function/closure. $v is the value of your $original_array.

提交回复
热议问题