Describes the very useful array function (reprint) associative array in several PHP4 equivalent to a hash array in Perl. I used to think that PHP didn't ...

Source: Internet
Author: User
Tags array compact hash mixed sort variable
perl| Function | Array describes the very useful "array" functions in several PHP4

1 void Extract (array var_array [, int extract_type] [, string prefix]])
Expands an associative array to the variable name and the value of the variable, and if there is a conflict, the following argument specifies the processing Method!
Such as:

<php?

/* Suppose that $var _array is a array returned from
Wddx_deserialize *

$size = "large";
$var _array = Array ("Color" => "Blue",
"Size" => "medium",
"Shape" => "sphere");
Extract ($var _array, Extr_prefix_same, "WDDX");

Print "$color, $size, $shape, $wddx _sizen";

?>

2 Array Compact (mixed varname [, mixed ...])
Instead of the above function, save the variable name and the value of the variable to the associative array!
Such as:
$city = "San Francisco";
$state = "CA";
$event = "SIGGRAPH";

$location _vars = Array ("City", "state");

$result = Compact ("event", "Nothing_here", $location _vars);

$result result is Array ("event" => "SIGGRAPH", "City" => "San Francisco", "state" => "CA").


3 bool In_array (mixed needle, array haystack)
To determine if there is a value in the array

4 void Natsort (array array)
Sort the array in natural numbers, when 12 will be at the back of 2
$array 1 = $array 2 = Array ("Img12.png", "Img10.png", "Img2.png", "img1.png");

Sort ($array 1);
echo "standard sort n";
Print_r ($array 1);

Natsort ($array 2);
echo "N natural sort N";
Print_r ($array 2);

The code output is:

Standard sort
Array
(
[0] => Img1.png
[1] => Img10.png
[2] => img12.png
[3] => Img2.png
)

Natural sort
Array
(
[3] => Img1.png
[2] => img2.png
[1] => Img10.png
[0] => Img12.png
)

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.