1. Basic form definition Array $array =array ();p Rint_r can print complex data type function 2. Define Array $array1 = Array (' John Doe ', ' ning ', ' Ling '); 3. Add a function to the array (an array of elements that need to be added, element 1, Element 2): Array_push ($array 1, ' Two dog ', ' dog Egg '); 4. Range (start, end, interval) returns an array of values $ARRAY3 = range (1,10,2); Echo ' <pre> '; Output Print_r ($array 3); Echo ' </pre> ';//array ([0] = 1 [1] = 3 [2] = 5 [3] = 7 [4] = 9) 5. Key-value pairs form $ar Ray5 = Array (); $array 5[' zhang '] = ' zhangsan '; $array 5[' wang '] = ' Wangbadan '; $array 5[' li '] = ' lisi '; $array 5[' tang '] = ' Tangdasha '; Echo ' <pre> ';p rint_r ($array 5); Echo ' </pre> ';//array ([Zhang] = zhangsan [Wang] = Wangbadan [Li] = lisi [tang] = Tangdasha) 6. Iterate over the array Foreachforeach ($array 5 as $key + $value) {echo $key. ‘ : ‘. $value. ' <br> ';} zhang:zhangsanwang:wangbadanli:lisitang:tangdasha Note: The name of the key is either the same, or the back will cover the previous 7. Array Length: Count ($array 6); 8. Delete the elements in the array $array7 = array (1,2,3,4); Array_splice ($array 7,1,1); Array_splice (array, index,length); 9. Two-d array $array9 = Array (' Autumn Dress ', ' Autumn Pants '), array (' cotton-padded ', ' trousers ', ' shoes '); Echo ' <pre > ';p rint_r ($ARRAY9); Echo ' </pre> ';//array ([0] = = Array ([0] = [1] = Autumn pants) [1] = = Array ([0] = coat [1] => ; Trousers [2] = shoes) 10. Key-value pairs form a two-dimensional array $array8 = array (' Autumn ' =>array (' Autumn clothes ', ' Autumn Pants '), ' Cotton ' =>array (' padded ', ' trousers ', ' trousers ')); Echo ' <pre > ';p rint_r ($array 8); Echo ' </pre> ';//array ([autumn] = = Array ([0] = Autumn clothes [1] = Autumn pants) [cotton] = Array ([0] =& Gt Coat [1] = trousers [2] = trousers) 11. Traverse the two-dimensional array traversal Array9$array9 = Array (' Autumn clothes ', ' Autumn Pants '), array (' padded ', ' trousers ', ' shoes ')); for ($i = 0; $i < Count ($array 9), $i + +) {for ($k = 0; $k < count ($array 9[$i]), $k + +) {echo $array 9[$i] [$k]. ' ---‘;} Echo ' <br> ';} Autumn Clothes---autumn trousers---cotton---trousers---shoes---
PHP Array 1