Methods for defining arrays in PHP

Source: Internet
Author: User


1, PHP defines the format of the array

Array name =array ();

such as: $aa =array ();//This defines an array,

Then assign values to the elements:

$aa [0]= "9016"; $aa [1]= "9017"; $aa [2]= "9018";

2, the PHP output array method:

foreach ($aa as $val) {echo$val;}

You can also assign a value directly when you define an array

$aa =array (0=> "9016",1=> "9017";2=> "9018");

3, the PHP array can also be used to subscript the character, not necessarily the number.

$AA ["Name"]= "Joan"; $AA ["Num"]= "9018"; $aa ["Email"]= "[email protected]";

You can do that.

$aa =array ("name" = "Joan", "num" = "9018", "email" = "[email protected]");

The element of a one-dimensional array is also defined as an array, which is a two-dimensional

$aa =array (0=> "A1",1=> "A2"), $bb =array (0=> "B1",1=> "B2"), $cc =array (0=> $aa;1=> $bb);

At this point, $cc [0] is an array, $CC [1] is an array, $CC is a two-dimensional array.

Similarly, three-dimensional, four-dimensional arrays can continue to be defined.

4 , the elements of an array are not only numbers and strings, but can be objects of a class.

Original:

Http://3women.blog.sohu.com/135437525.html

Methods for defining arrays in PHP

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.