Case analysis of international trade practice example analysis of common array processing methods in PHP

Source: Internet
Author: User
Tags php example
1.array_shift () Moves the first cell out of the array and returns it, which is sometimes convenient for the first cell of the array to be handled separately.

Copy the Code code as follows:


$tmparray = Array ("1", "2", "3", "4");
$tmparray = Array_shift ($tmparray);
Print_r ($tmparray);
?>


2.array_chunk () splits an array into multiple arrays, followed by parameters that control the number of array cells.

Copy the Code code as follows:


$tmparray = Array (' A ', ' B ', ' C ', ' d ', ' e ');
Print_r (Array_chunk ($tmparray, 2));
?>


This function works well in some loops, such as I want to put the obtained data into n rows, m columns. If we do not directly loop, of course, with nested loops can be implemented, but too much trouble, if first used array_chunk () This function first to process and then return the new array, it is very convenient.
3.array_push () presses the incoming value into the end of the array.

Copy the Code code as follows:


$tmparray = Array ("A", "B");
Array_push ($tmparray, "C", "D");
Print_r ($tmparray);//array ([0] = a[1] =>b[2] =>c[3] =>d)
?>


4.array_unshift () Inserts the incoming cell into the array as a whole

Copy the Code code as follows:


$tmparray = Array ("A", "B");
$resarray = Array_unshift ($tmparray, "C", "D");
Print_r ($resarray)//array ([0] = a[1] =>b[2] =>c[3] =>d)
?>


5.array_unique the array to remove the weight and return a new

Copy the Code code as follows:


$tmparray = ("a" = "a", "B" = "B", "C" = "C", "D" = "B");
$resarray = Array_unique ($tmparray);//("a" = "a", "B" = "B", "C" = "C");
?>

The above describes the international trade practice case analysis of common array processing methods in PHP example analysis, including the International Trade practice case analysis of the content, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    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.