Array_slice and Array_flip in PHP array functions

Source: Internet
Author: User
Look at Array_slice first.

The function of Array_slice is to take a part out of an array, and there are two ways to use it:

$arr =array (' a ' = = ' AA ',           ' b ' = = ' BB ', ' c ' + = ' cc ',           ' d ' = ' dd ');//start with the 1th data in the array (the array itself starts with 0) and fetch two items. $tmp =array_slice ($arr), Showobj ($tmp);//start with the third data in the array, and fetch two items: $tmp =array_slice ($arr, -3,3); Showobj ($tmp);

Next look at the output:

Array (2) {
["B"]=>
String (2) "BB"
["C"]=>
String (2) "CC"
}


Array (3) {
["B"]=>
String (2) "BB"
["C"]=>
String (2) "CC"
["D"]=>
String (2) "DD"
}

The Showobj function is a var_dump package that is used to print specific objects.

function Showobj ($OBJ) {  echo '
";  Var_dump ($OBJ);  echo "
";}

Here's a look at the Array_flip function:
Array_flip is used to Exchange $arr=array_flip ($arr) of the key values in the array; showobj ($arr);

Output Result:

Array (4) {
["AA"]=>
String (1) "a"
["BB"]=>
String (1) "B"
["CC"]=>
String (1) "C"
["DD"]=>
String (1) "D"
}

The above describes the PHP array functions in the Array_slice and array_flip, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.