PHP output array-detailed description of printed array instances

Source: Internet
Author: User
Output array elements in PHP can be achieved through output statements, such as echo statements and print statements. However, in this output mode, only one element in the array can be output, and the array structure can be output through the print_r () function. Suppose there is an array:

 

What will the above code output? You can try the above results locally.

We usually use print_r to print the array (of course, var_dump can also be used, but the structure is not clear)

bool print_r ( mixed $expression [, bool $return ] )

Please print

print_r($names);

When the second parameter is true, print_r does not directly print the array, but returns the printed content as a string.

echo print_r($names, true);

We can use echo to print a string, integer, and floating point type, but we cannot use it to print an array.

An array is composed of a series of elements. to print an array, each element should be printed, rather than the entire array.

Output array elements in PHP can be achieved through output statements, such as echo statements and print statements. However, in this output mode, only one element in the array can be output, and the array structure can be output through the print_r () function.

The syntax format is as follows:

bool print_r(mixed expression)

If the expression parameter of the function is a common integer, string or real variable, the variable itself is output. If this parameter is an array, all elements in the array are output based on the key values and elements in sequence.

An instance of the print_r () function output array:

 "PHP", 2 => "Chinese", 3 => "net"); print_r ($ array);?>

Output result:

[Recommended tutorials]

1. related topic recommendations: php Array (Array)

The above is the detailed description of the PHP output array-print the array instance. For more information, see other related articles in the first PHP 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.