Php array summation array intersection content replacement operations _ PHP Tutorial

Source: Internet
Author: User
Php array summation array intersection content replacement and other operations. This tutorial focuses on intermediate data operations, replacing array elements with intersection content, and searching for array content. This tutorial focuses on intermediate data operations and array elements. this tutorial describes intermediate data operations, replacing array elements with intersection content, and searching for array content.

This tutorial focuses on intermediate data operations, replacing array elements with intersection content, and searching for array content.
*/
$ Input = array ("red", "green", "blue", "yellow"); // defines the original array
Array_splice ($ input, 2); // perform the removal operation
Print_r ($ input); // output the processed result
$ Input = array ("red", "green", "blue", "yellow"); // defines the original array
Array_splice ($ input, 1,-1); // execute the removal operation and specify the length.
Print_r ($ input); // output the processed result
$ Input = array ("red", "green", "blue", "yellow"); // defines the original array
Array_splice ($ input, 1, count ($ input), "orange"); // you can perform the removal operation and specify the length and content.
Print_r ($ input); // output the processed result
$ Input = array ("red", "green", "blue", "yellow"); // defines the original array
Array_splice ($ input,-, array ("black", "maroon"); // replace the content with an array
Print_r ($ input); // output the processed result
$ Input = array ("red", "green", "blue", "yellow"); // defines the original array
Array_splice ($ input, 3, 0, "purple ");
Print_r ($ input); // output the processed result

//
$ Sweet = array ('a' => 'apple', 'B' => 'bana'); // define the original array
$ Fruits = array ('sweet '=> $ sweet, 'sour' => 'limon'); // define another array
Function test_print ($ item, $ key) // user-defined function
{
Echo "$ key holds $ itemn"; // Two parameters are output.
}
Array_pai_recursive ($ fruits, 'Test _ print'); // recursively calls a user-defined function for members of the logarithm Group

// Sum
$ A = array (2, 4, 6, 8); // defines the original array
Echo "sum (a) =". array_sum ($ a). "n"; // sum
$ B = array ("a" => 1.2, "B" => 2.3, "c" => 3.4); // define the original array
Echo "sum (B) =". array_sum ($ B). "n"; // sum

// Array intersection
Function strcasecmp ($ key1, $ key2)
{
If ($ key1 = $ key2) // if the two parameters are equal
Return 0; // return 0
Else if ($ key1> $ key2) // if the first one is greater than the last one
Return 1; // return 1
Else // if the first one is smaller than the last one
Return-1; // return-1
}
$ A1 = array ("a" => "green", "B" => "brown", "c" => "blue", "red "); // define array 1
$ A2 = array ("a" => "green", "B" => "brown", "yellow", "red"); // define array 2
Print_r (array_uintersect_uassoc ($ a1, $ a2, "strcasecmp", "function"); // calculates the intersection of two arrays

// Array intersection
$ A = array ("a" => "green", "B" => "brown", "c" => "blue", "red "); // define array 1
$ B = array ("a" => "green", "B" => "brown", "yellow", "red"); // define array 2
$ Result = array_uintersect ($ a, $ B, "strcasecmp"); // calculates the array intersection.
Print_r ($ result );

Replace and search for the array content. This tutorial focuses on intermediate operations on data, seeking array elements...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.