PHP part of the function of the detailed

Source: Internet
Author: User
This article mainly share with you the PHP part of the function of the detailed, mainly in the way of code and we share, hope to help everyone.

1, Array_diff_assoc ($arr 1, $arr 2, $arr 3 ...) function: Compare the key names and key values of two arrays and return the difference set

Cases:

<?php$a1=array ("2" = "This_2", "3" = "This_3", "4" = "This_4", "5" and "this_5"); $a 2=array ("1" = "This _1 "," 2 "=" This_2 "," 3 "=" This_3 "), $result 1 = ARRAY_DIFF_ASSOC ($a 1, $a 2); The array can be exchanged sequentially, or it can be multiple arrays var_dump ($result 1); >

Printing results:

Array (size=2)  4 = String ' This_4 ' (length=6)  5 = String ' This_5 ' (length=6)

2. Array_keys () function: Returns a new array containing all the key names in the array

Cases:

<?php$a1=array ("2" = "This_2", "3" = "This_3", "4" = "This_4", "5" and "This_5"); $result 2 = Array_keys ($a 1 ); Var_dump ($result 2);? >

Printing results:

Array (size=4)  0 = int 2  1 = int 3  2 = int 4  3 = int 5

3. Array_key_exists () Function: Checks whether the specified key name exists in an array, returns true if the key name exists, or False if the key name does not exist.

Cases:

<?php$a1=array ("2" = "This_2", "3" = "This_3", "4" = "This_4", "5" and "this_5"); if (Key_exists ("2", $a 1)) {echo "yes!";} Else{echo "no!";}? >

Output Result:

yes!

4. Sort () function: Sorts the array in ascending order

5. Rsort () function: Sort in descending order of array

6. Asort () function: sort associative arrays in ascending order based on values

7. Ksort () function: Sort the associative array in ascending order according to the key

8. Arsort () function: sort associative arrays in descending order based on values

9. Krsort () function: Sort the associative array in descending order according to the key

10. Count () function: Returns the number of elements in an array

Cases:

<?php$a1=array ("2" = "This_2", "3" = "This_3", "4" = "This_4", "5" and "This_5"); $result 3 = count ($a 1); echo $result 3;? >

Output Result:

4

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.