How to get the first few elements of the php array: first create a new php file; then create an array; finally use the "array_splice" function to get the first three elements from the "$arr" array.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
Create a new php file and name it test.php. Used to explain how PHP takes the first few elements from an array as a new array.
In the test.php file, use the header() method to set the encoding format of the page to utf-8.
In the test.php file, create an array for testing.
In the test.php file, use the array_splice function to take the first three elements from the $arr array, delete the following elements, and form a new array.
In the test.php file, use print_r to output the processed array.
Open the test.php file in the browser to view the results.
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to get the first few elements of php array. For more information, please follow other related articles on the PHP Chinese website!