Array sorting problem!

Source: Internet
Author: User
Array sorting problem! $ A = array ('Zhang San' => 'Zookeeper pick up the parameter ', 'Lily' => 'one click and pick up the parameter', 'Wang Wu' => 'Zookeeper ', 'Sun 6' => 'Sun 6', 'Chen 7' => 'wan wowang Yi Erqing ');

Sort the array by the numeric size represented by the man without changing the index. the output result should be in the following format:

Array ', 'Sun 6' => 'Sun 6', 'Chen 7' => 'wan wowang Yi Erqing ');

The code should be as simple as possible. I am a newbie and use the array sorting function for final sorting.


Reply to discussion (solution)

$ A = array ('Zhang San' => 'Zookeeper pick up the parameter ', 'Lily' => 'one click and pick up the parameter', 'Wang Wu' => 'Zookeeper ', 'Sun 6' => 'Sun 6', 'Chen 7' => 'Lou WOWO '); $ t = array_map ('cton ', $ a); array_multisort ($ t, $ a); print_r ($ a); function cton ($ s) {$ dw = array ('pick' => 10, 'hangzhou' => 100, 'hangzhou' => 1000, 'wan' => 10000); $ digital = array ('0' => 0, 'yi' => 1, 'ER' => 2, 'san' => 3, 'Si '=> 4, 'Wu' => 5, 'loan' => 6, 'login' => 7, 'login' => 8, 'login' => 9); $ ar = preg_split ('/('. join ('|', array_keys ($ dw )). ')/', $ s,-0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); for ($ I = 0; $ I
   
  
Array ([Li Si] => Yi Yu pick up [Zhang San] => Si Yu pick up 3 [Wang Wu] => Xiao Yu [Sun 6] => Yi Han Lu pick up [Chen Qi] => Si Wan Wu Yi Eryi)

$ Ar = preg_split ('/('. join ('|', array_keys ($ dw )).')/',
$ S,-0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );

Can you comment on this section? Thank you.

'/('. Join ('|', array_keys ($ dw )).')/'
Construct a regular rule string such as/(pick up | unlock | fail | )/

As for how to use the preg_split function, the manual has made it clear.

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.