Print_r and Var_dump output array _php techniques in PHP

Source: Internet
Author: User

The Print_r () and Var_dump () functions can print out the entire array contents and structure.

Print_r ()

Using the Print_r () function, you can print out the entire array contents and structure, displaying the keys and elements in a certain format. Note the Print_r () function is not only for printing, it is actually used to print easily understandable information about variables.

Grammar:

BOOL Print_r (mixed expression) Example:

<?php
$arr _age = Array (a);
Print_r ($arr _age);
? >

Run the example output:

Array ([0] => [1] => [2] => 25) To view the output of the page source code, you can see more readable format:

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

Like the Print_r () function, the Var_dump () function can also be used to print the data and structure of an array. However, the Var_dump () function is more powerful than print_r (), and can print multiple variables at the same time and give the variable type information.

Example:

<?php
$arr _age = Array (a);
Var_dump ($arr _age);
? >

Run the example output:

Array (3) {
 [0]=>
 int (a)
 [1]=>
 int ()
 [2]=>
 int
}

The Print_r () and Var_dump () functions are typically used by the debugger, and more often by using echo to output specific array cell values.

The above PHP print_r and var_dump output array is a small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.

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.