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

前端 未结 23 2157
没有蜡笔的小新
没有蜡笔的小新 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

    In PHP>=5.3 and based on Luc M's answer (the first one) you can make use of closures like this

    array_walk_recursive($aNonFlat, function(&$v, $k, &$t){$t->aFlat[] = $v;}, $objTmp);
    

    I love this because I don't have to surround the function's code with quotes like when using create_function()

提交回复
热议问题