Home > Backend Development > PHP Tutorial > Introducing several very useful array functions in php4. Associative arrays are equivalent to hash arrays in PERL. I always thought there was no such thing in PHP..._PHP Tutorial

Introducing several very useful array functions in php4. Associative arrays are equivalent to hash arrays in PERL. I always thought there was no such thing in PHP..._PHP Tutorial

WBOY
Release: 2016-07-13 17:28:30
Original
779 people have browsed it

Introducing several very useful "array" functions in php4 1 void extract (array var_array [, int extract_type ][, string prefix]]) expands an associative array into variable names and variable values. If there is a conflict, the following parameters will be used Specify the processing method! For example:
"blue", "size" => "medium", "shape" => "sphere"); extract ($var_array, EXTR_PREFIX_SAME, "wddx"); print "$color, $size, $shape , $wddx_sizen"; ?> 2 array compact (mixed varname [, mixed ...]) Contrary to the above function, save the variable name and variable value into an associative array! For example: $city = "San Francisco"; $state = "CA"; $event = "SIGGRAPH"; $location_vars = array ("city", "state"); $result = compact ("event", "nothing_here" , $location_vars); $result The result is array ("event" => "SIGGRAPH", "city" => "San Francisco", "state" => "CA"). 3 bool in_array (mixed needle, array haystack) Determine whether there is this value in the array 4 void natsort (array array) Sort the array using the natural number method, then 12 will be ranked behind 2 $array1 = $array2 = array ("img12.png", "img10.png", "img2.png","img1.png"); sort($array1); echo "standard sortn"; print_r($array1); natsort($array2); echo "nnatural sortn"; print_r($array2 ); The code output is: Standard sorting Array ( [0] => img1.png [1] => img10.png [2] => img12.png [3] => img2.png ) Natural sorting Array ( [3] => img1.png [2] => img2.png [1] => img10.png [0] => img12.png )

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531781.htmlTechArticleIntroducing several very useful array functions in php4 1 void extract (array var_array [, int extract_type ][, string prefix]]) Expand an associative array into variable names and variable values, such as...
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