PHP output array-print array instance in detail

Source: Internet
Author: User
Suppose you have an array:

<?php$arr=["PHP", "Chinese", "net"];echo $arr;? >

What will the above code output? Above results you can try again locally.

We typically use Print_r to print an array (Var_dump is also possible, but not structurally clear)

BOOL Print_r (mixed $expression [, BOOL $return])

Please try to print

Print_r ($names);

When the second argument is true, Print_r does not print the array directly, but instead returns the printed content as a string

Echo Print_r ($names, true);

We can use Echo to print a string, integer, float, but we can't use it to print an array.

Arrays are made up of a series of elements, and if you want to print, you should print each element instead of the entire array.

The output of an array of elements in PHP can be achieved through output statements, such as ECHO statements, print statements, and so on. However, this output can only be used to output an element in an array, and the Print_r () function allows you to output the structure of the arrays.

The syntax format is as follows:

BOOL Print_r (mixed expression)

If the function's argument expression is a normal integer, string, or real variable, the variable itself is output. If the parameter is an array, the key values and the order of the elements output all elements in the array.

An instance of the output array of the Print_r () function:

<?phpheader ("content-type:text/html; Charset=utf-8 "), $array = Array (1=>" PHP ",2=>" Chinese ",3=>" net ");p Rint_r ($array); >

The output is:

"Related tutorials Recommended"

1. Related topics: "PHP array"

Related Article

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.