Home  >  Article  >  Backend Development  >  How to print array in php

How to print array in php

藏色散人
藏色散人Original
2019-09-18 09:42:1525994browse

How to print array in php

php method of printing arrays

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

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

Run this example output:

Array
(  [0] => 1      [1] => 2     [2] => 3
)

var_dump() function

Example:

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

Run this example output:

array(3)

For more PHP knowledge, please visit the PHP Chinese website PHP Tutorial!

The above is the detailed content of How to print array in php. 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