PHP echo,print_r (expression), var_dump (expression) difference, print_rvar_dump_php tutorial

Source: Internet
Author: User

PHP echo,print_r (expression), var_dump (expression) difference, print_rvar_dump


All three are PHP statements with output functionality, but print_r (expression), var_dump (expression) is a function, and Echo is simply a language structure, not a function, and therefore cannot be part of an expression.
For the 8 data types in PHP,


What kind of data can I output in PHP echo,print_r,var_dump? What difference do they have?

Echo ' outputs a string ';//can only output strings and numbers

print_r-Print easy-to-understand information about variables, typically with an output array structure

var_dump-information about printing variables, typically used for array and object printing

It's clear that you use it yourself.

What is the difference between echo (), print (), and Print_r () in PHP?

There are four ways to output a string. Echo

Print ()

printf ()

Print_r ()
Echo
Multiple values can be output at one time, and multiple values are separated by commas. Echo is a language structure (language construct), not a real function and therefore cannot be used as part of an expression.

Grammatically correct: Echo "Hello", "World";
Syntax error: Echo ("Hello", "World");
Print ()
The function print () prints a value (its arguments) and returns True if the string is successfully displayed, otherwise false. For example, if (!print ("Hello, World")) {

Die ("is not a listening to me");

}
printf ()
printf () originates from printf () in the C language. The function outputs a formatted string.
Syntax: printf (format,arg1,arg2,arg++)
format Specifies the string and how the variable is formatted;
Arg1, arg2, + + etc parameters will be inserted into the main string percent percent (%) Symbol. This function is executed step-by. In the first% symbol, insert arg1, insert arg2 at the second% symbol, and so on.
Example:? php

$str = "Hello";

$number = 123;

printf ("%s World". Day number%u ", $STR, $number);

?>
#Results ======
Hello World. Day Number 123

If the% symbol is more than the arg parameter, you must use a placeholder. After the placeholder is inserted in the% symbol, it consists of a number and a "\$". See Example 3.
Example:? php

$number = 123;

printf ("With 2 decimals:%1\$.2FBR/>with no decimals:%1\ $u", $number);

?>
#Result
With 2 decimals:123.00
With no decimals:123

Print_r () and Var_dump ()
Print_r () can simply print the string and the number, and the array is displayed with the enclosed key and the list of merit, beginning with an array. For example, $a = Array (' name ' = ' Fred ', ' age ' = ' + ', ' wife ' = ' Wilma ');

Print_r ($a);
Output:array

{

[Name] + Fred

[Age] = 15

[Wife] = Wilma

}
objects are the same. For example, class P {

var $name = ' nat ';

// ...

}

$p = new P;

Print_r ($p);
Output:object

{

[Name] = NAT

}
But the result of Print_r () output Boolean and null is meaningless, because all are printed &quo ... Remaining full text >>

http://www.bkjia.com/PHPjc/886484.html www.bkjia.com true http://www.bkjia.com/PHPjc/886484.html techarticle php echo,print_r (expression), var_dump (expression), print_rvar_dump are all PHP statements with output functionality, but print_r (expression), Var_dump (expression) is a function, echo just ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.