【发布时间】:2015-03-18 21:04:51
【问题描述】:
我需要打印一个可以直接粘贴到代码中的复杂 PHP 变量。 print_r 不这样做,因为当我使用它时,我得到这样的东西:
Array
(
[cost] => 218.16
[discount] => Array(...)
[description] => Cost Not Included
[quantity] => 1
)
不能立即粘贴到 PHP 代码中。相反,我需要这样的东西(添加逗号,括号更改为&符号等)
array
(
'cost' => '218.16',
'discount' => array(...),
'description' => 'Cost Not Included',
'quantity' => 1,
),
怎么做?
目前我在我的文本编辑程序中手动完成...
【问题讨论】:
-
链接问题将
print_r的输出转换为PHP 可读形式。类似于迂回方式,但与第一步以 PHP 可读形式打印出数组不同。