本文介绍了内爆和分解多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP 中是否有递归爆炸和内爆多维数组的函数?

Are there any functions for recursively exploding and imploding multi-dimensional arrays in PHP?

推荐答案

您可以通过编写递归函数来实现:

You can do this by writing a recursive function:

function multi_implode($array, $glue) {
    $ret = '';

    foreach ($array as $item) {
        if (is_array($item)) {
            $ret .= multi_implode($item, $glue) . $glue;
        } else {
            $ret .= $item . $glue;
        }
    }

    $ret = substr($ret, 0, 0-strlen($glue));

    return $ret;
}

至于爆炸,这是不可能的,除非您为字符串提供某种形式的结构,在这种情况下,您将进入序列化领域,其功能已经存在:序列化, json_encode, http_build_query 等等.

As for exploding, this is impossible unless you give some kind of formal structure to the string, in which case you are into the realm of serialisation, for which functions already exist: serialize, json_encode, http_build_query among others.

这篇关于内爆和分解多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 08:13
查看更多