These days on the Internet to read a lot about PHP array functions related knowledge, feel Confucius "warm so know new" really not false, here is I summed up some experience, hope to everyone has help.
The array in PHP is actually an ordered graph, which is a type that maps values to keys. This type is optimized in many ways, so you can use it as a real array, or list (vector), hash list (an implementation of the graph), dictionaries, collections, stacks, queues, and more possibilities. Because you can use another PHP array as a value, you can also easily emulate a tree. Explaining these structures is beyond the scope of this manual, but you will find at least one example for each structure. To get more information on these structures, we recommend that you refer to the external works on this broad topic, and note some of my PHP array functions as follows:
1. Splitting a 1-d array into a 2-dimensional array array_chunk ()
- $ Input_array =array (' A ', ' B ', ' C ', ' d ', ' e ');
2. Compare 2 arrays, ARRAY_DIFF_ASSOC () or Array_diff (), if the return value is empty, representing two arrays of the same, otherwise it will be different.
3. Use a function to filter the values in the array array_filter ()
- Functionodd ($var) {
- return ($var%2==1);
- }
- Functioneven ($var) {
- return ($var%2==0);
- }
- $ Array array1 =array ("a" =>1, "b" =>2, "c" =>3, "D "=>4," e "=>5);
- $ Array array2 =array (6,7,8,9,10,11,12);
- echo "Odd:n";
- Print_r (Array_filter ($array 1, "odd"));
- echo "Even:n";
- Print_r (Array_filter ($array 2, "even"));
- ?>
4.array_map () functions The callback function on the cell of the given array, its arguments can be an array, or it can be multiple arrays, and the parameters of the callback function must be the same as the parameters that call it.
- An example of a single argument that multiplies each value in the array by multiplying it by 3 times
- Functioncube ($n) {
- return$n* $n * $n;
- }
- $ a = Array (1,2,3,4,5);
- $ b = Array_map ("Cube", $a);
- Print_r ($b);
- ?>
- Examples of multiple array parameters
- Functionshow_spanish ($n, $m) {
- return "Thenumber$niscalled$minspanish";
- }
- Functionmap_spanish ($n, $m) {
- ReturnArray ($n=>$m);
- }
- $ a = Array (1,2,3,4,5);
- $ b = Array ("Uno", "dos", "Tres", "Cuatro", "Cinco");
- $ C = Array_map ("Show_spanish", $a, $b);
- Print_r ($c);
- $ D = Array_map ("Map_spanish", $a, $b);
- Print_r ($d);
- ?>
- Output results
- Printoutof$c
- Array
- (
- [0]= > Thenumber1iscalledunoinspanish
- [1]= > Thenumber2iscalleddosinspanish
- [2]= > Thenumber3iscalledtresinspanish
- [3]= > Thenumber4iscalledcuatroinspanish
- [4]= > Thenumber5iscalledcincoinspanish
- )
The above is about the PHP array function of the relevant summary, we have to memorize ah.
http://www.bkjia.com/PHPjc/446539.html www.bkjia.com true http://www.bkjia.com/PHPjc/446539.html techarticle these days on the Internet to read a lot about PHP array functions related knowledge, feel Confucius "warm so know new" really not false, here is I summed up some experience, hope to everyone has help ...