search

Home  >  Q&A  >  body text

php print_r prints a blank

Tested it on thinkphp
print_r("test:",array(1, 2, 3, 4, 5, 6));
var_dump("test1:",array( 1, 2, 3, 4, 5, 6));

I found that the top one is always blank
The bottom one is normal

What is this problem? Please answer

为情所困为情所困2798 days ago645

reply all(5)I'll reply

  • 漂亮男人

    漂亮男人2017-05-16 13:13:27

    That is caused by improper use of your function.
    The print_r function has two parameters ,
    The first parameter is required and is the variable to be printed. For example, "test" (string), 123 (integer), 123.01 (floating point), true (Boolean), etc.;
    The second parameter is optional and is a Boolean value. If true, it is not printed, but its output is returned as the result.

    <?php
    $a = print_r('使用了true,所以我在这里只是变量值咯<br />',true);
    
    print_r('没使用true,直接输出咯<br />');
    
    echo $a;

    After running, the results are as follows:

    没使用true,直接输出咯
    使用了true,所以我在这里只是变量值咯

    In short, var_dump prints multiple sets of variable information, print_r prints a set of variable information

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 13:13:27

    http://php.net/manual/en/func...
    See the manual

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-16 13:13:27

    print_r($var1,$var2); When $var2 is true, no output will be output; but if your second parameter is an array, will no error be reported? ?

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-16 13:13:27

    The second parameter of print_r is of bool type, your usage is wrong.

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 13:13:27

    print_r does not output information but returns information when the second parameter is true. Your second parameter is a non-empty array and will be implicitly converted to true. If it is an empty array, it will be implicitly converted to false.

    reply
    0
  • Cancelreply