PHP inverse array and permutation array key and value explanation

Source: Internet
Author: User
PHP inverse array and permutation array keys and values

Inverse array element order

The Array_reverse () function resets the order of the elements in the array. The form is as follows:

?

Array array_reverse (array array [, Boolean Preserve_keys])

?

If the optional parameter Preserve_keys is set to true, the key mapping is persisted. Otherwise, the re-placed values will correspond to the first

The corresponding key z in the previous position

?

$states = Array ("Delaware", "Pennsylvania", "New Jersey");p Rint_r (Array_reverse ($states));//Array ([0] = new Jerse y [1] = Pennsylvania [2] = Delaware)

?

Can be compared with the results obtained when Preserve_keys is enabled

?

$states = Array ("Delaware", "Pennsylvania", "New Jersey");p Rint_r (Array_reverse ($states, 1));//Array ([2] = new Je Rsey [1] = Pennsylvania [0] = Delaware)

?

Arrays that use associative keys are unaffected by Preserve_keys, and the key mappings are always maintained for associative arrays.

Permutation array keys and values

The ARRAY_FL IP () function displaces the role of the keys and their corresponding values in the array. The form is as follows Z

?

Array array_flip (array array)

?

Here is an example of this function Z

$state = Array ("Delaware", "Pennsylvania", "New Jersey"), $state = Array_flip ($state);p rint_r ($state);

?

This example returns the following result Z

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

?

?

"To the fishing" detailed tutorial See "PHP and MySQL program design," The 52nd page, OK Bookstore (www.okpdf.com) to provide free ebook download address: 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.