search
HomeBackend DevelopmentPHP ProblemWhat are the php output methods?

php output method: 1. Use the echo statement to output, for example "echo 'hi!'"; 2. Use the print statement to output; 3. Use the printf() function to output, for example "printf("hi") "; 4. Use print_r() to output; 5. Use var_dump() to output.

What are the php output methods?

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

PHP output method

echo

echo is a language structure that can be used without or with parentheses. : echo or echo(). (Strings can contain HTML tags)

echo 'helloworld!';

print statement

print is also a language structure, brackets may or may not be used Brackets: print or print().

print('helloworld!'); //输出成功返回1,失败返回0。

printf() function

The printf() function can also realize output, and can output ordinary strings and formatted output. Example:

<?php
$a=20;
printf("输出:");
printf("a=%f",$a);
?>

Output:

输出:a=20.000000

print_r()

print_r Displays easy-to-understand information about a variable Information, if string, integer or float is given, the variable value itself will be printed.

If array is given, the keys and elements will be displayed in a certain format. object is similar to an array.

1. You must add brackets when using: print_r().

2. print_r() will move the pointer of the array to the end. Use reset() to return the pointer to the beginning.

<?php
$a = array (&#39;a&#39; => &#39;apple&#39;, &#39;b&#39; => &#39;banana&#39;, &#39;c&#39; => array (&#39;x&#39;,&#39;y&#39;,&#39;z&#39;));
echo "<pre class="brush:php;toolbar:false">";
print_r ($a);
echo "
"; ?>

Output:

Array
(
    [a] => apple
    [b] => banana
    [c] => Array
        (
            [0] => x
            [1] => y
            [2] => z
        )

)

var_dump()

Print the relevant information of the variable, this Functions display structural information about one or more expressions, including the expression's type and value. Arrays will expand values ​​recursively, showing their structure through indentation.

<?php
$var_name=array(99,&#39;w3resource&#39;,67899.99, array(&#39;X&#39;,&#39;Y&#39;,1));
var_dump($var_name);
?>

Output:

array (size=4)
  0 => int 99
  1 => string &#39;w3resource&#39; (length=10)
  2 => float 67899.99
  3 => 
    array (size=3)
      0 => string &#39;X&#39; (length=1)
      1 => string &#39;Y&#39; (length=1)
      2 => int 1

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What are the php output methods?. 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

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 Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools