如何从 var_dump() 结果创建数组

发布于 2024-11-25 08:35:15 字数 991 浏览 7 评论 0原文

我 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尾戒 2024-12-02 08:35:15

只需使用赋值运算符 = 分配新数组即可。

$nuarr = $first_array;

现在 $nuarr$first_array 的相同副本。

您还可以使用 var_export

$nuarr = var_export($first_array, true);

Just assign the new array using assignment operator =

$nuarr = $first_array;

Now the $nuarr is an identical copy of your $first_array.

You can also use the var_export

$nuarr = var_export($first_array, true);
断念 2024-12-02 08:35:15

你没有提到为什么要这样做。如果您需要的只是数组到字符串的机制,反之亦然,请考虑使用 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() and unserialize() rather than var_dump().

腻橙味 2024-12-02 08:35:15

如果你想打印出一个数组以便你可以清楚地看到它的结构,你不能执行以下操作吗?

echo '

'.print_r($array,1)',

';

我知道它没有使用 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文