We are introduced here is in the array to increase the associative array, this is a multi-dimensional array, I would like to give you a few examples, I hope that the students will help you. In the"PHP Array add element Method Summary This article describes how to add elements to an array, then I want to add$arrayWhat about the elements of =array (' title ' = ' php tutorial ')? Array_push, Array_pop, Array_shift, array_unshift These functions are designed for index arrays of numeric types. To implement an associative array, you can use the Array_merge method or the + operator to begin by adding array element 1 to the array. Methods for adding array elements to PHP: (1) Adding array elements by assigning values:$states[' name ']= ' Tom ';(2) int Array_push (array target_array,mixed variable [, mixed variable ...]) function adds variable to target_ Returns true at the end of the array, or FALSE, where variable can be multiple. (3) int array_unshift (array target_array,mixed variable [, mixed variable ...]) function adds variable to target_array array header, returns true on success, Otherwise, false is returned, where variable can be multiple. All existing numeric keys are modified accordingly, and the associated keys are not affected. (4) Array array_pad (array Target_array,integer length,mixed pad_value) increases the size of the Target_array to the length specified. Is it OK to use Array_push or Array_unshift two methods? The answer is the specific method of negation: 1. Use the Array_merge method to implement a function code similar to Array_unshift to add elements at the beginning as follows to copy code <?php$queue= Array (' A ', ' B ');$queue= Array_merge (Array (' front ' = ' hello '),$queue);/*array ([Front] = Hello [0] + a [1] + b) */?>2.+ operator code copy Code as follows <?php$queue= Array (' A ', ' B ');$queue= Array (' front ' + = ' Hello ') +$queue;? > output is the same as using the Array_merge method. 3. Add the associated array element code at the end of the element as follows to copy the code <?php$queue= Array (' A ', ' B ');$queue[' front '] = ' hello ';/* output Array ([0] = a [1] = = b [front] = =) */?>
A summary of methods for adding associated elements to the PHP array (associative array add Element)