Home > Backend Development > PHP Tutorial > PHP array classification and array creation examples explained

PHP array classification and array creation examples explained

jacklove
Release: 2023-03-27 15:04:02
Original
2039 people have browsed it

This article explains PHP array classification and array creation examples.

1. Array classification

1. Index array

Array whose index value is an integer

2.Associative array

Index value For arrays of strings, use strings as indexes, which makes programming more user-friendly!

This is very rare in other programming languages, but it will be widely used in PHP during the development process.

It is extremely convenient to use!

2. Array creation

Creating arrays in PHP is very flexible. Unlike many other programming languages, PHP does not need to

specify the size of the array when creating it. You can store any type of data in the same array without even declaring it before using it.

. You can create an array by directly assigning values ​​to the array elements.

. Use the array() language structure to create an array.

1. Create an array by directly assigning values ​​​​to the array elements

Variable name [index value] = data content; the index value can be an integer or a string, or it must be written (default is an index array) 2. Use the array() language structure to create an array. Variable name=array(key1=>value1,...);

##