Home > Backend Development > PHP Tutorial > International trade practice case analysis Example analysis of commonly used array processing methods in PHP

International trade practice case analysis Example analysis of commonly used array processing methods in PHP

WBOY
Release: 2016-07-29 08:38:42
Original
1226 people have browsed it

1.array_shift() moves the first unit of the array out and then returns it. This is very convenient for sometimes the first unit of the array needs to be processed separately.

Copy the code The code is as follows:


$tmparray = array("1", "2", "3", "4");
$tmparray = array_shift ($tmparray);
print_r($tmparray);
?>


2.array_chunk() splits an array into multiple arrays, and the following parameters control the number of array units.

Copy the code The code is as follows:


$tmparray = array('a', 'b', 'c', 'd', 'e');
print_r(array_chunk($ tmparray, 2));
?>


This function is very useful in some loops. For example, I want to put the obtained data into N rows and M columns. It will definitely not work if we loop directly. Of course, we can use nested loops to achieve it, but it is too troublesome. It would be very convenient if we use the array_chunk() function to process it first and then return the new array.
3.array_push() pushes the passed in value to the end of the array.

Copy code The code is 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() will The incoming unit is inserted into the array as a whole

Copy the code The code is 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 deduplicates the array and returns a new array

Copy the code The code is as follows:


$tmparray = ("a" => "a ","b" => "b","c" => "c","d" => "b");
$resarray = array_unique($tmparray);//("a" = > "a","b" => "b","c" => "c");
?>

The above has introduced the practical case analysis of international trade and the analysis of common array processing methods in PHP, including the content of practical case analysis of international trade. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template