Home > Backend Development > PHP Problem > php print_r what is

php print_r what is

藏色散人
Release: 2023-03-01 17:40:02
Original
10008 people have browsed it

php print_r is a built-in function in php, used to print variables and display them in a more understandable form. The syntax of this function is "bool print_r (mixed $expression [, bool $return])" .

php print_r what is

PHP print_r() function

print_r() function is used to print variables to make it easier Demonstration of understanding.

PHP version requirements: PHP 4, PHP 5, PHP 7

Syntax

bool print_r ( mixed $expression [, bool $return ] )
Copy after login

Parameter description:

$expression: variable to be printed, if Given a variable of type string, integer or float, the variable value itself will be printed. If an array is given, the keys and elements will be displayed in a certain format. object is similar to an array.

$return: Optional, if true, the result will not be output, but the result will be assigned to a variable, if false, the result will be output directly.

Return value

$return If set to true, there will be a return value, which is an easy-to-understand string information.

Example

<?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;));
print_r ($a);
?>
Copy after login

The output result is:

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

Set $return parameter:

Example

<?php
$b = array (&#39;m&#39; => &#39;monkey&#39;, &#39;foo&#39; => &#39;bar&#39;, &#39;x&#39; => array (&#39;x&#39;, &#39;y&#39;, &#39;z&#39;));
$results = print_r ($b, true); // $results 包含了 print_r 的输出结果
?>
Copy after login

The above information has no output result. Because the output result is assigned to the $results variable.

For more related technical articles, please visit PHP Chinese website!

The above is the detailed content of php print_r what is. 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