php 打印所有定义的变量和值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5529827/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 21:43:14  来源:igfitidea点击:

Printing all defined variables and values

php

提问by Vish

<?php echo ‘<pre>'; print_r(get_defined_vars()); echo ‘</pre>'; ?>

This is just giving me the arrays for defined variables but not priniting out any variables. How can I print values too?

这只是给了我定义变量的数组,而不是打印出任何变量。我怎样才能打印值?

Also what function can I use to output all the defined variables in this format:

另外我可以使用什么函数以这种格式输出所有定义的变量:

Variable name | Variable Type [int, array, string, bool] | Variable defined on line | Variable defined in script | Variable used times | Variable Value

变量名 | 变量类型 [int, array, string, bool] | 在线定义的变量 | 脚本中定义的变量 | 可变使用次数 | 变量值

回答by Steve

Have you tried:

你有没有尝试过:

var_dump(get_defined_vars());

http://php.net/manual/en/function.var-dump.php

http://php.net/manual/en/function.var-dump.php

The php documentation should help.

php 文档应该会有所帮助。

回答by BugFinder

You can make your own debug output, by iterating through the array of returned to display gettype, value and name. However, the where it was defined, how much its been used, you cant do. PHP doesnt work that way

您可以创建自己的调试输出,方法是遍历返回的数组以显示 gettype、value 和 name。然而,它被定义在哪里,它被使用了多少,你做不到。PHP 不能那样工作