为什么我的打印数组末尾有1?

Pet*_*ter 4 php printing arrays

这是一个超级简单的数组打印,但是当我使用print_r时,我终于到了.

<?php 
  $user_names = array(1, 2, 3, 4);
  $results = print_r($user_names);
  echo $results;
?>
Run Code Online (Sandbox Code Playgroud)

然后我得到:

 Array
 (
     [0] => 1
     [1] => 2
     [2] => 3
     [3] => 4
 )
 1
Run Code Online (Sandbox Code Playgroud)

Thi*_*ter 12

print_r已打印数组 - 不需要echo返回值(true因此1转换为字符串时最终会结束):

当return参数为TRUE时,此函数将返回一个字符串.否则,返回值为TRUE.

以下也可以正常工作:

$results = print_r($user_names, true);
echo $results;
Run Code Online (Sandbox Code Playgroud)

它根本没有任何意义,除非你不总是在得到它们之后立即显示结果.