Home > Article > Backend Development > Summary of using php arrays, summary of php arrays_PHP tutorial
In PHP, arrays are divided into two categories: index arrays and associative arrays. The two can be used alone or mixed.
1. One-dimensional array
The definition of a one-dimensional array is also very simple. There are two commonly used methods:
1.1 Direct assignment
1: 29c19bbcbb31a64f89da72211d94e174a directly.First of all, your way of writing is really different. Nowadays, PHP is more common in curly bracket writing
(1) For weak language PHP, it does not need to be initialized like a strict language. It is automatically initialized when used. . So after declaring the array, it can be used. And sometimes there is no need to declare it, such as writing $i = 1.25 directly; if an error is reported in a rigorous language, PHP can use it like this.
(2) The default index of the array starts from 0 and then increases by 1. count($arr) is the number of array elements. Assuming n is the number of elements in the current array, then $arr[n-1] is the element with the largest index. Adding $arr[n] is equivalent to adding an element at the end of the array. In fact, you can write $arr[] = $ss, and the effect is the same.
(3) Algorithm idea problem, which means that if a natural number can be divided by a smaller prime number than it, then it is not a prime number.
(4) There is nothing wrong with the program....