Example of a string in an array of PHP and sort

Source: Internet
Author: User

Use the Array_flip () function in PHP to weight a set of strings, and then use sort () function to order, to achieve some practical application effects.

The source code is as follows:

<?php
$strArr = Array (
' www.111cn.net ', '
Xiao ', '
Rui ',
' Xiao ',
' Dai ',
' www.111 Cn.net ',
' hello,friend '
);
$STRARR = Array_flip (Array_flip ($STRARR));
Invert (Array_flip () function: Reverses the key value and value in an array, and if the same value is present, the last key will be its value, and if the data type of the value in the original array is not an integer or a string, the function complains. Sort
($STRARR);//
Print_r ($STRARR);
? >

This example is actually very simple is that the array is heavy, there are many methods on the internet here only a hope for everyone useful.

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.