This article mainly for array intersection, determine whether the key exists in the array, merge two arrays, data sorting, add array, delete array elements, randomly extract array elements and other instances.
This article mainly for array intersection, determine whether the key exists in the array, merge two arrays, data sorting, add array, delete array elements, randomly extract array elements and other instances.
*/
$array 1=array ("a" = "green", "Red", "blue");
$array 2=array ("b" = "green", "yellow", "red");
$result =array_intersect ($array 1, $array 2);//Calculate intersection and assign values
Print_r ($result);
//
$search _array=array (' first ' =>1, ' second ' =>4); Defining arrays
if (array_key_exists (' first ', $search _array))//Determine if the key exists in the array
{
echo "The ' first ' element is in the array"; Output the appropriate information
}
//
$ar 1=array ("Color" =>array ("favorite" = "Red"), 5);
$ar 2=array ("Color" =>array ("favorite" = "green", "Blue"));
$result =array_merge_recursive ($ar 1, $ar 2); Merging two arrays returns an array of results
Print_r ($result); Output results
//
$array 1=array ("Color" = "red", 2,4);
$array 2=array ("A", "B", "color" = "green", "shape" = "trapezoid", 4);
$result =array_merge ($array 1, $array 2); Merging two arrays
Print_r ($result); Output result Content
//
$ar 1=array ("Ten", 100,100, "a"); Defining Arrays 1
$ar 2=array (1, 3, "2", 1); Defining Arrays 2
Array_multisort ($ar 1, $ar 2); Sort 2 arrays
Var_dump ($ar 1); Print a sorted result
Var_dump ($ar 2); Print a sorted result
//
$stack =array ("Orange", "banana", "apple", "rasp tutorial Berry"); Define an array
$fruit =array_pop ($stack); The last element out of the stack
Print_r ($stack); Show results
//
$stack =array ("Orange", "banana"); Defining the original array
Array_push ($stack, "apple", "raspberry"); Performing a push stack operation
Print_r ($stack); Displays the result and returns four values
//
Srand (float) microtime () *10000000); Seeding a random number generator
$input =array ("Neo", "Morpheus", "Trinity", "Cypher", "tank"); Defining the original array
$rand _keys=array_rand ($input, 2); Random selection of array elements
Print $input [$rand _keys[0]]. " n "; Display randomly selected array elements, respectively
Print $input [$rand _keys[1]]. " n ";
http://www.bkjia.com/PHPjc/445396.html www.bkjia.com true http://www.bkjia.com/PHPjc/445396.html techarticle This article mainly for array intersection, determine whether the key exists in the array, merge two arrays, data sorting, add array, delete array elements, randomly extract array elements and other instances. This ...