What is the php print array function?

藏色散人
Release: 2023-02-25 22:18:01
Original
3954 people have browsed it

What is the php print array function?

What is the php print array function?

php has two functions for printing arrays: print_r() function and var_dump() function

The print_r() function is used to print variables and display them in a more understandable form.

var_dump() function is used to output relevant information about variables.

var_dump() function displays structural information about one or more expressions, including the type and value of the expression. Arrays will expand values ​​recursively, showing their structure through indentation.

print_r() function

Example:

<?php 
  $arr_test =
array(1, 2, 3);
 print_r($arr_test);
?>
Copy after login

Run this example output:

Array
(  [0] => 1      [1] => 2     [2] => 3
)
Copy after login

var_dump() function

Example:

<?php
$arr_test = array(1, 2,
3);
var_dump($arr_test);
?>
Copy after login

Run this example output:

array(3) 
{  
[0]=> int(1)
[1]=> int(2)
[2]=> int(3)
}
Copy after login

The var_dump() function is used the same as the print_r() function. However, the var_dump() function is more powerful than print_r(). It can print multiple variables at the same time and give the type information of the variables.

For more PHP knowledge, please visit PHP Chinese website!

The above is the detailed content of What is the php print array function?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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