What are the differences between echo, print() and print_r()?

墨辰丷
Release: 2023-03-25 19:16:01
Original
3384 people have browsed it


This article mainly introduces the differences between echo, print() and print_r(). Interested friends can learn about it.

1. What is the difference between echo, print() and print_r()?
echo is a language structure with no return value. print is a function that returns a value of type int. print_r() is a function that returns a bool type value and outputs the value of the variable according to the structure.
2. In HTTP 1.0, the meaning of status code 401 is (unauthorized, the current request requires user verification); if a "File not found" prompt is returned, the header function can be used, which The statement is (header("HTTP/1.0 404 Not Found")).
3. $str="cd";
$$str="hotdog"; <==> $cd="hotdog";
$$str.="ok";
echo $cd; <==> "hotdogok".
4. echo 3 . print(2) . print(4) . 5 . 'c';//45c2131 (For such questions, please refer to the previous blog post "About Operation analysis of mixed echo, print and '.' operators in PHP " is introduced in ")
5.echo '2'.print(2) 3 ;//521
6.echo print(8) . 'a'; //8a
7.print(8) . 'a'; // 8a
8. Use PHP to print out the time of the previous day in the format of 2006-5-10 22:21:21
echo date("Y-m-d H:i:s ", strtotime("-1 day"));
9.echo $var = $value;//$value
10.echo 0 == " a"; // 1
11. ($tmp = 0) == "a" ? 1: 2;
echo $tmp; // 0
12. $tmp = (0 == "a") ? 2: 3;
echo $tmp; // 2
13. $tmp = 0 == "a" ? 2: 3;
echo $tmp; // 2
14. $b = '1d9' ;
echo $b; // 1e0
$a='1d9'; $a = $a 1; echo $a;//If the operation is '1d9 'Only take the number before the character =>'1' and then participate in the operation: 1 1=2.
15. $array = new ArrayObject();
if(empty($array))
{ echo '0'; }
else
{ echo '1'; }
var_dump($array); //object(ArrayObject)#1 (1) { ["storage":"ArrayObject":private]=> array(0) { } }
The answer is 1.
16.$a = "hello"; $b = &$a; unset($b); $b = "world"; Variable The value of a is ("hello")
$a = "hello"; $b = &$a; unset($b); @var_dump($a,$b);// string(5) "hello" NULL
b points to the memory space of a, but a will not be deleted when b is deleted.
17. A group of monkeys line up in a circle and number them sequentially according to 1, 2,...,n. Then start counting from the 1st one, count to the mth one, kick it out of the circle, start counting from behind it, count to the mth one, kick it out..., and continue in this way until the end. Until there is only one monkey left, that monkey is called the king. Programming is required to simulate this process, input m, n, and output the number of the last king. Hint: Joseph Ring Question

 function yuesefu($n,$m) { 
     $r=0; 
     for($i=2; $i<=$n; $i++) 
     { 
        $r=($r+$m)%$i; 
     }
      return $r+1; 
   } 
   echo(yuesefu(5,3));
Copy after login


18.echo count("abc"); // 1 -- Count the number of cells in the array or the number of attributes in the object.
19. How to implement string flipping?
echo strrev("string");//gnirts
20. What is the difference between the statement include and require?
require (): If the file does not exist, a fatal error will be reported. The script will stop execution; include(): If the file does not exist, a warning will be given, but the script will continue to execute.
21 .if ($a = 100 && $b = 200) {
var_dump($a, $b); // true, 200
}
22. $arr = ['1', '2'];
foreach($arr as $k => $v){
if($k == 0){
$adm = '3333';
} elseif($k == 1){
$ adm [] = 'Baidu';
##}
#} ## error. Fatal error: [] operator not supported for strings
23. Regarding the following code, the correct statement is:

<?php
   class Test{
      public function __get($str){
        echo &#39;access__get::&#39;.$str.&#39;-->&#39;;
        return [&#39;fd&#39;=>&#39;hy&#39;];
      }
   }
  $b = new Test();
  //var_dump($b->member);打印出[&#39;fd&#39;=>&#39;hy&#39;];
  var_dump(empty($b->member));//打印出什么????
   ==》true
Copy after login
24.

$bA = true; $bB = false;
$b1 = $bA and $bB; $b2 = $bA && $bB;
var_dump($b1); //true
var_dump($b2); //false
var_dump($bA and $bB);//false
var_dump($bA && $bB); //false
var_dump($b1);=》Because "=" is "and" has high priority, so the assignment operation is performed first, and then the and operation is performed, but the result is not saved.
25. The correct statement about Math in js is: (a,c,d)
a.Math.ceil(m) returns a value greater than or equal to m The value
b.Math.round(m) returns a value greater than or equal to m, for example, Math.round(-3.1) returns -3;
c. Math.floor(m) returns a value less than or equal to m
d.Math.floor(-2.9); returns -3
26.Error in PHP What are the types?
There are roughly three types of errors encountered in PHP.
Tips: These are very normal messages, not major errors, and some will not even be displayed to users. For example, access a variable that does not exist.
Warning: This is a serious error. A warning message will be displayed to the user, but it will not affect the output of the code, such as including some non-existent files.
Error: This is a really serious error, like accessing a non-existent PHP class.
27. Which of the following functions are wrong: c
a.getimagesize()
b.imagesx()
c.file_get_content()
d.imagesy()
28.What is the output [assuming 1.js file exists] (b)
a. No output, but an alert will be issued
b. No output, no alert
If you write the alert statement in the 1.js file, it will alert.
29. Functions and methods are the same, but their names are different (b)
a. Yes, functions and methods are the same, but their names are different
b. Different, and not the same concept
30.echo 0 == '';Will this sentence be printed? (a)
a.1 b.0
31.

$str = >>>EOD
I saw a dog yesterday.
EOD;
echo $str;
The above will output: (c)
a.I saw a dog yesterday
b. Output empty string
c. Syntax error, there will be no echo result
32. Which of the following functions can open a file for reading and writing operations on the file? (c)
a.fget()
b.file_open()
c.fopen()
d.open_file()
33.php is a compiled language (x) ,PHP is an interpreted language (√)
34.var_dump(strpos('mrwagon',626)); //int(1)
The second parameter needle of this strpos is not a string! If it is a string, it will look false at first glance. But numbers must be converted into corresponding ASCII code characters for processing. The convertible range of ASCII code is 0~255.626/256=2...114, the corresponding character of 114 is r, so the result is 1.
35.$arr = array('a','b','c');
foreach($arr as $k => $v) {
echo key($arr), "=>", current($arr),' ';//1=>b 1 =>b 1=>b
}
36.Which function is used for natural sorting: natsort().
37._() is the abbreviation of which function: gettext().
38. In ThinkPHP3, the directory structure is as follows:
Application
-----User
-----User---Action----->UserAction.php
---- -User---Module---->UserModule.php
-----Api
-----Api---Action------>ApiAction.php
-----Api---Module----->ApiModule.php
How to call things in Api/Module under User's Action?
There is a method in ApiModule.php: getUserNameByUID. How do I call the getUserNameByUID method in ApiModule.php in UserAction.php? ? ?
D('Api/Api')->getUserNameByUID();
39.
$arr ​​= ['hello', 'world'];
while ($word = each($ arr)){
$x = $arr;
}
The value of $x at this time is (infinite loop). (Can’t understand!!!)
40. Get the variable a b of http://hdwo.net/?a b=1 in the URL. The following is the correct method
$_GET['a_b']
41 .Get the variable a.b in the URL http://hdwo.net/?a.b=1, the following is the correct method
$_GET['a_b']

Related recommendations:

Detailed introduction and usage of phpecho function

Related knowledge and application of PHP 5 echo and print statements


php implements testing of var_dump and echo output multi-variables



The above is the detailed content of What are the differences between echo, print() and print_r()?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template