1 One: function Introduction2 we know that the operation of the array in PHP is a very important step, there is no array, can not be described as PHP, so its importance is self-evident! 3 An array is a set of data that organizes a series of data to form an operational whole. Each entity of an array contains two items: A key and a value. 4Demo Address: http://www.ijquery.cn/phpfunction/BaseFunctionArray/DemoArray.php5: http://Www.ijquery.cn/phpfunction/BaseFunctionArray/BaseFunctionArray.zip6 7 8 Two: function code9<?PHPTen One //=============================== Common Array method =============================== A - $arr=Array("K0" = "a", "K1" and "B", "K2" and "C"); - the //returns the number of array elements - $int=Count($arr); - - //determines whether the first parameter element in the array element of the second argument + $bool=In_array("B",$arr); - + //returns a new array of all the key values in parentheses that do not change the original array A $array=Array_keys($arr); at - //determines whether the second parameter's array has the first parameter's key value, returns the True or False - $bool=array_key_exists("K1",$arr); - - //returns a new array of all the element values in the original array, with the key value starting from 0 and the original array unchanged - $array=array_values($arr); in - //returns the key value pointed to by the current array pointer to $key=Key($arr); + - //returns the element value pointed to by the current array pointer the $value= Current($arr); * $ //returns an array of the current array pointers to the element's key and element values, then pushes the pointer to the next bit, and the last pointer to an empty element returns an empty//returned array with four fixed key values corresponding to the element values that are the key value of the returned element and the element value, where 0, ' key ' The key value corresponds to the return element key value, 1, the ' value ' key value corresponds to the returned element valuePanax Notoginseng $array= each($arr); - the //first, the array pointer is pushed to the next bit, and then the value of the element pointed to after the pointer moves + $value=Next($arr); A the //pushes the array pointer to the previous bit and returns the value of the element pointed to when the pointer moves + $value=prev($arr); - $ //resets the array pointer to the first element and returns the value of the element $ $value=Reset($arr); - - //points The array pointer to the last element and returns the last element value the $value=End($arr); - Wuyi //appends the argument of the first argument as an element to the end of the first parameter array, the index is counted from the smallest unused value, and the array length after the return the $int=Array_push($arr, "D", "DFSD"); - Wu //Add all parameters after the first parameter array as elements to the beginning of the first parameter array, the key value is re-accumulated from the first element at 0, the key value of the original non-numeric value remains unchanged, the original element sort position is unchanged, and the array length after the return - $int=Array_unshift($arr, "T1", "T2"); About $ //returns the last element value extracted from the end of the array and rejects the last element from the original array - $value=Array_pop($arr); - - //Array_pop Instead, extracts the value of an element from the header of an array and rejects an element from the original array . A $value=Array_shift($arr); + the //let the first parameter array reach the second parameter value length, add the third argument as an element to the end of the first parameter array, the index is counted from the minimum unused value, and the original array does not change - $array 1=Array_pad($arr, ten, "T10"); $ the //returns a new array that rejects the extra repeating elements in the original array, without changing the original array the $array=Array_unique($array 1); the the //break the original array key value to re-order the value of the value of the aspartame code from small to large, the index from the number 0, the re-meter - $int=Sort($array); in the //As opposed to sort, Ascol the value of the element value in descending order of size, the index is recalculated from 0 the $int=Rsort($array); About the //returns an array of the values of each element in the first parameter array, followed by the value of the key, to the parameter two arrays, the length of the two arrays must be identical, the original array does not change the $array=Array_combine(Array("A", "B", "C", "D", "E"),$arr); the + //combines two numbers and returns the original array unchanged - $array=Array_merge($arr,Array("A", "B", "C")); the Bayi //in the first parameter array, starting from the second parameter value position, intercept the array key value of the third parameter value length + element and return, array first element position from 0 the $array=Array_slice($arr, 2,1); the - //The interception function is just like array_slice (), except that the intercept is removed from the original array . - $array=Array_splice($arr, 2,1); the the //the first parameter as the first element, each increment of the value of the parameter three, and then as an element in the array, until the value reaches the value of the parameter two is stored in the array and return the array//parameter one, the parameter two can be a number, can be a single character, the individual characters according to Ascol code value calculation, The third parameter does not write default 1 per increment the $array=Range(3,9,2); the - //The corresponding relationship between the original array element and corresponding key value is re-randomly returned to true or false. the $bool=Shuffle($arr); the the //computes the value of all numeric elements in the array and94 $int=Array_sum(Array("A", 2, "CSSF"))); the the the //splits an array into new array blocks, each element of the new array is an array, and the new array has several elements within each element determined by parameter two//the third parameter determines whether the key value of the element retains the original key value is not writable, True is reserved, false by default is not preserved98 $array=Array_chunk(Array("A" = "a", "B", "C", "D", "E", "F", "G", "H"), 2,true); About - //Json_encode () converts an array into a JSON-formatted string to return101 $arr=Array(' k1 ' = ' val1 ', ' k2 ' = ' val2 ', ' K3 ' =Array(' v3 ', ' v4 '));102 Echo $encode _str= Json_encode ($arr);103 104 //Json_decode () converts a JSON format string to an object that can cast an array of values, which must be enclosed in double quotation marks when the key and value in the JSON format string are quoted. the $decode _arr= (Array) Json_decode ($encode _str);106 Var_dump($decode _arr);
Array functions in PHP