PHP array: create an array

Source: Internet
Author: User
Theformalmethodofcreatinganarrayis & nbsp; tousethearray () function. Itssyntaxis: $ listarray ('appes', 'banas', & nbsp; 'oranges'); Arraysautomati

The formal method of creating an array is? To use the array () function. Its syntax is:
$ List = array ('append', 'banas ',? 'Oranges ');
Arrays automatically begin their indexing? At 0, unless otherwise specified. In that? Example-which doesn' t specify an index? For the elements-the first item, apples, is automatically indexed at 0, the second? Item at 1, and the third at 2 .? You can assign the index when using? Array ():
$ List = array (1 => 'append', 2 =>? 'Banas', 3 => 'oranges ');
Because PHP is very liberal when it comes? To blank space in your scripts, can you? Make this structure easier to read? Writing it over multiple lines:

$list = array (    1 => 'apples',    2 => 'bananas',    3 => 'oranges');

Finally, the index value you specify doesn't? Have to be a number-you can use strings? As well. This indexing technique is practical
For making more meaningful lists. As? Example, you cocould create an array that? Records the soup of the day for each day? Of the week, as in the following script. This? Example will also demonstrate how you? Can, and cannot, print out an array (which? Has already been demonstrated but is? Worth rehashing ).

 

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.