| This article introduces the related content of array pointer operations in php, which is the operation guide for commonly used php array functions. if you need it, refer to it. Php array operation function: array (key = value); create an array // display the array print_r ($ array); // use the compact () function to create an array, use the parameter as the unit of the new array; $ newArray = compact (red, green, yellow, blue, array); // Use extract () the function converts the elements in the array to the variable extract ($ exArray); echo $ key1 $ key2 $ array ("key" => "value "); create an array // display the array print_r ($ array); // use the compact () function to create an array and use the parameter as the unit of the new array; $ newArray = compact ("red ", "green", "yellow", "blue", "array"); // use the extract () function to convert the elements in the array to the variable extract ($ exArray ); echo "$ key1 $ key2 $ key3 $ key4 $ key5 "; ※Check value and key array_key_exists ($ key, $ array); // Check the array key in_array ($ value, $ array); // check the value in the array ※Get value // use array_values () to obtain the array value $ carValues = array_values ($ car); // Retrieve the array key name $ twoKeys = array_keys ($ two ); key ($ array); // output the key name of the current unit // after defining the array, use current () to get the value of the current unit $ red = current ($ array ); list ($ red, $ green) = $ array; // assign values in the array to variables, $ array = array ("red", "green "); each ($ two); // returns the key and value of the current cell in the array. ※Traversing the array foreach ($ two as $ subArray); // traversing the array while (list ($ key, $ value) = each ($ array )) {echo "$ key => $ value,"; // use each to traverse the array} ※Fill in the array. // fill in the array array_pad ($ array, + 3, "shuzhi") to the left and right. // The parameter 2 is filled from the left to the right, $ array1 = array_fill (5, 5, "test"); // use array_fill () to fill in the value of this array. The value is test, starting from 5th units, fill in a total of 5 units // fill in the array key name $ keys = array ('string', 5, 10, 'str '); $ array3 = array_fill_keys ($ keys, "Array Value"); // use the array_filp () function to exchange key names and values $ speed = array_flip ($ speed ); // use the array_splice () function to replace the value of 6th units with 7 $ output = array_splice ($ input, 6, 0, 7); // use the array_splice () function to delete the array unit, only the first five units $ output = array_splice ($ input, 5); $ array1 = range (10,100, 10); // use the third parameter of the range () function, set step values between units ※Sort shuffle ($ array); // disrupt the array order // use array_multisort () to sort the three arrays. array_multisort ($ sort1, $ sort2, $ sort3 ); // sort the array and maintain the index relationship asort ($ array); // sort the test array in reverse order and maintain the index relationship arsort ($ array ); // use ksort () to sort the array key names ksort ($ array); // use the krsort () function to sort the key names in reverse order krsort ($ array); // use sort () sort the test array [by key name] sort ($ array); // use natsort () to sort [natural sorting, sort by values] case sensitive to unit values natsort ($ array); // use the natcasesort () function to sort [natural sorting], but ignore the value case sensitive natcasesort ($ array ); // use the array_reverse () function to sort the array elements in reverse order $ newArray = array_reverse ($ array, TRUE); // retain the original key name when set to TRUE ※Intersection, difference set // use array_diff () to calculate the difference set of the three arrays [comparison of array values] $ result = array_diff ($ dog1, $ dog2, $ dog3 ); // use array_diff_assoc () to calculate the difference set of the three arrays [comparison of values and key names] $ result = array_diff_assoc ($ dog1, $ dog2, $ dog3 ); // use array_diff_key () to calculate the difference set of the three arrays [comparison key name] $ result = array_diff_key ($ dog1, $ dog2, $ dog3); // use array_intersect () calculate the intersection of the three arrays [compare the array values] $ result = array_intersect ($ dog1, $ dog2, $ dog3); // use array_intersect_assoc () calculate the intersection of the three arrays [comparison of values and key names] $ result = array_intersect_assoc ($ dog1, $ dog2, $ dog3); // use array_intersect_key () calculate the intersection of the three arrays [comparison key name] $ result = array_intersect_key ($ dog1, $ dog2, $ dog3 ); ※Merge arrays // use the array_merge () function to merge arrays $ result = array_merge ($ array1, $ array2, $ array3, $ array4, $ array5); array_rand ($ input, 10); // randomly retrieve 10 units count ($ array, COUNT_RECURSIVE); // display the number of array units. The value of 2 can only be 1 or COUNT_RECURSIVE, and sometimes traverse multi-dimensional arrays. ※Warehouse receiving/warehouse picking/warehouse receiving/warehouse picking, add two values, 7 and 8, to the end of the array, array_push ($ array, 7, 8); // remove the elements starting with the array from the array, array_shift ($ array ); // add to the beginning of array array_unshift ($ array ); |