如何从 var_dump() 结果创建数组
我 var_dump 和数组并打印了一个值,如何从结果创建一个数组。数组是生成一个方法,我显然不知道数组的结构。
Array ( [0] => gapiReportEntry 对象 ( [metrics:gapiReportEntry:private] => Array ( [visits] => 4 ) [dimensions:gapiReportEntry:private] => Array ( [year] = > 2011 年 [月] => 07 [日] => 20 ) ) [1] => gapiReportEntry 对象 ( [metrics:gapiReportEntry:private] => Array ( [visits] => 32 ) [dimensions:gapiReportEntry:private] => Array ( [year] => 2011 [month] => 07 [日]=>13)))
以上是 var_dump 结果。
我尝试重新创建它
$nuarr = 数组(); $nuarr[0] = array("metrics:gapiReportEntry:private"=>array("visits"=>4),"dimensions:gapiReportEntry:private"=>array("year"=>2011,"月"=>07,"日"=>20)); $nuarr[1] = array("metrics:gapiReportEntry:private"=>array("visits"=>10),"dimensions:gapiReportEntry:private"=>array("year"=>2011,"月"=>07,"日"=>10));
但它不会返回相同的 var_dunp 值。
有人可以帮我构建数组吗...
I var_dump and array and got a value printed, how do i create an array from the result. the array is generated a method and i clearly dont know the structure of the array.
Array ( [0] => gapiReportEntry Object ( [metrics:gapiReportEntry:private] => Array ( [visits] => 4 ) [dimensions:gapiReportEntry:private] => Array ( [year] => 2011 [month] => 07 [day] => 20 ) ) [1] => gapiReportEntry Object ( [metrics:gapiReportEntry:private] => Array ( [visits] => 32 ) [dimensions:gapiReportEntry:private] => Array ( [year] => 2011 [month] => 07 [day] => 13 ) ))
the above is the var_dump result.
I tried to recreate it
$nuarr = array();
$nuarr[0] = array("metrics:gapiReportEntry:private"=>array("visits"=>4),"dimensions:gapiReportEntry:private"=>array("year"=>2011,"months"=>07,"day"=>20));
$nuarr[1] = array("metrics:gapiReportEntry:private"=>array("visits"=>10),"dimensions:gapiReportEntry:private"=>array("year"=>2011,"months"=>07,"day"=>10));
but it doesn't return the same var_dunp value.
Could anyone structure the array for me...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需使用赋值运算符
=
分配新数组即可。现在
$nuarr
是$first_array
的相同副本。您还可以使用 var_export
Just assign the new array using assignment operator
=
Now the
$nuarr
is an identical copy of your$first_array
.You can also use the var_export
你没有提到为什么要这样做。如果您需要的只是数组到字符串的机制,反之亦然,请考虑使用
serialize()
和unserialize()
而不是var_dump().
You don't mention why you want to do this. If what you need is just an array-to-string and vice versa mechanism, consider using
serialize()
andunserialize()
rather thanvar_dump()
.如果你想打印出一个数组以便你可以清楚地看到它的结构,你不能执行以下操作吗?
echo '
';
我知道它没有使用 var_dump(),但它会产生所需的结果,不是吗?
If you want to print out an array so that you can clearly see its structure, couldn't you do the following?
echo '<pre>'.print_r($array,1)',</pre>';
I know it isn't using var_dump(), but it would produce the desired result, wouldn't it?