PHP reverse placement array and replacement array keys and values

Source: Internet
Author: User
PHP reverse array and replacement array key and value explanation reverse array element order array_reverse () function reverse the order of elements in the array. The format is as follows :? Arrayarray_reverse (arrayarray [, booleanpreserve_keys])? If the optional parameter preserve_keys is set to TRUE, key ING is maintained. Otherwise, the reset values correspond to the previous PHP reverse array and replacement array keys and values.

Reverse array element order

The array_reverse () function reverses the order of elements in the array. The format is as follows:

?

array array_reverse(array array [, boolean preserve_keys])

?

If the optional parameter preserve_keys is set to TRUE, key ING is maintained. Otherwise, the values after placement will correspond

The corresponding key z at the previous position

?

$states = array("Delaware" , "Pennsylvania" , "New Jersey");print_r(array_reverse($states));// Array ( [0] => New Jersey [1] => Pennsylvania [2] => Delaware )

?

You can compare it with the result obtained when preserve_keys is enabled.

?

$states = array("Delaware" , "Pennsylvania" , "New Jersey");print_r(array_reverse($states, 1));// Array ( [2] => New Jersey [1] => Pennsylvania [0] => Delaware )

?

The array using the correlated Key will not be affected by preserve_keys, and key ING will always be maintained for the associated array.

Replace the array key and value

The array_fl ip () function replaces the role of the input key and corresponding value in the array. The format is as follows: z

?

array array_flip(array array)

?

The following is an example of this function z

$state = array("Delaware" ,"Pennsylvania" , "New Jersey");$state = array_flip($state);print_r($state);

?

In this example, the following result is returned:

Array ( [Delaware] => 0 [Pennsylvania].=> 1 [New Jersey] => 2 )

?

?

For more information about the tutorial, see [PHP and mysql programming]. on page 6, OK bookstore (www.okyun.com) provides free e-books: Click to download.

?

?

?

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.