search
HomeBackend DevelopmentPHP TutorialWhat are the differences between echo, print() and print_r()?

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

May 15, 2018 pm 05:50 PM
echoprintthe difference


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));


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

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!

Statement
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
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)