PHP array classification, array creation example explained

Source: Internet
Author: User
This article explains the PHP array classification and array creation examples.

First, array classification

1. Indexed arrays

An array of indexed values as integers

2. Associative arrays

Indexed values are arrays of strings, using strings as indexes, which makes programming more user-friendly!

This is very rare in other programming languages, but it is used extensively in the development process in PHP,

Extremely convenient to use!

Second, array creation

The creation of arrays in PHP is very flexible, unlike many other programming languages where PHP does not need to create arrays

, specify the size of the array, even if you don't need to declare it before using the array, or you can save it in the same group

Store any type of data.

You can create an array by assigning a value directly to an array element.

. Create an array using the array () language structure.

1. Create arrays by assigning values directly to an array element

Variable name [index value]= data content; The index value can be an integer or a string, or it cannot be written (default is an indexed array) 2. Create an array variable name using the array () language structure =array (key1=>value1,......);


<!--? php

/*

Create Array Method One

*/

$student [index value]= specific value $student[0]=10; $student [1]= ' idiot '; $student [2]=true; $student [3]=60.5; $student [3]= ' units get complete ';
You need to use the Print_r () function to output the specific contents of the array//print_r ($student); Var_dump ($student); $student 1[' num ']=10; $student 1[' name ']= ' idiot '; $student 1[' sex ']=true; $student 1[' Grade ']=60.5;var_dump ($student 1); The method of using the specific data inside the array//array variable name [index value];echo $student [1];</pre><pre class= "Brush:java;" ><!--? php/*

Create Array Method Three

*/

$student =array (the index value =--> the specific value,.......); $student =array (10, ' idiot ', true,60.5);//one-dimensional array var_dump ($student); $student 1=array (0=>10, 1=> ' idiot ', 2=>true, 3=>60.5); Var_dump ($student 1); $student 2=array (' num ' =>11, ' name ' = ' dish forcing ', ' sex ' =>true, ' Grade ' =>80.5, 10=> ' dqwdwqdwq '); Var_dump ($student 2);?><!--? php//Two-dimensional array, multidimensional array $students=array (    0=-->array (1, ' idiot ', true,60.5),    1 = >array (2, ' vegetable forcing ', true,80.5),    2=>array (3, ' Pit Force ', false,85.5));/* $students =array (        Array (1, ' idiot ', true,60.5 ),        Array (2, ' vegetable forcing ', true,80.5),        Array (3, ' Pit Force ', false,85.5)); */Var_dump ($students); Echo $students [0][1];? >

This article PHP array classification, array creation examples to explain, more relevant content please focus on PHP Chinese web.

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.