PHP has an array of features which

PHP array is a very powerful and flexible data types. The following is a PHP array with some of the features:

1, may be used as an array or string of digital key

1

$arr = [1 => 'ok', 'one' => 'hello'];

2, the array can be sequentially read

1

2

3

foreach($arr as $key => $value){

 echo $arr[$key];

}

3, the random read elements in the array

1

2

3

4

5

$arr = [1 => 'ok', 'one' => 'hello', 'a' => 'world'];

  

echo $arr['one'];

  

echo current($arr);

4, the length of the array is variable

1

2

3

4

5

$arr = [1, 2, 3];

  

$arr[] = 4;

  

array_push($arr, 5);

It is based on these characteristics, we can easily achieve collection, stack, lists, dictionaries and other data structures using arrays in PHP.

Guess you like

Origin www.cnblogs.com/heyue0117/p/11827830.html