array( "a" => "orange", "b" => "banana","c" => "apple&"/> array( "a" => "orange", "b" => "banana","c" => "apple&">

PHP数组转字符串如何转

WBOY
Release: 2016-06-13 13:31:36
Original
869 people have browsed it

PHP数组转字符串怎么转
例如数组:$myarr = array ( "fruits" => array( "a" => "orange", "b" => "banana","c" => "apple"));
怎么转换成字符串:
$str='array ( "fruits" => array( "a" => "orange", "b" => "banana","c" => "apple"))'

也就是原封不动的把数组转成字符串



------解决方案--------------------
echo var_export($myarr, true);

显示会略微不同,符合php语法规范
------解决方案--------------------
附赠参考资料

PHP code

var_export ― 输出或返回一个变量的字符串表示

描述
mixed var_export ( mixed $expression [, bool $return ] )
此函数返回关于传递给该函数的变量的结构信息,它和 var_dump() 类似,不同的是其返回的表示是合法的 PHP 代码。 

您可以通过将函数的第二个参数设置为 TRUE,从而返回变量的表示。 

比较 var_export() 和 var_dump(). 


<pre class="brush:php;toolbar:false">
<?php $a = array (1, 2, array ("a", "b", "c"));
var_export ($a);

/* 输出:
array (
  0 => 1,
  1 => 2,
  2 => 
  array (
    0 => 'a',
    1 => 'b',
    2 => 'c',
  ),
)
*/

$b = 3.1;
$v = var_export($b, TRUE);
echo $v;

/* 输出:
3.1
*/
?>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template