PHP 数组到字符串等效 [英] PHP Array to String equivalent

查看:25
本文介绍了PHP 数组到字符串等效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人有将数组转换为字符串的递归解决方案.

I'm wondering if anyone has a recursive solution to converting an array to a string.

我的意思是:

具有以下内容的数组 $args:

An array $args that has the following contents:

Array
(
    [0] => $hello
    [1] => 411px
    [Jeeves] => Array
        (
            [compiling] => 1
        )

)

<小时>

调用arr_to_string($args)后的结果:

array($hello,"411px", "Jeeves" => array("compiling" => 1));

注意:它识别前面的 $ 符号,因此不会添加引号.它对数字也一样.

Note: It recognizes the $ sign in front and therefore does not add quotes. It does the same for numbers.

有人有任何解决方案或可以指出我正确的方向吗?

Anyone have any solution or can point me in the right direction?

谢谢!马特·穆勒

推荐答案

看起来你很在意

  • var_export — 输出或返回一个变量的可解析字符串表示

不过这不会给你 $hello,因为 $hello 不能在数组中.它始终只是变量的值,而不是变量名称.如果您想要 '$hello',请在将其插入数组时将其放入单引号中,例如将其作为字符串插入,而不是作为变量插入.

That won't give you $hello though, because $hello cannot be in an array. It's always just the value of the variable, not the variable name. If you want '$hello', put it into single quotes when inserting it to the array, e.g. insert it as a string, not as a variable.

这篇关于PHP 数组到字符串等效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆