Home > Backend Development > PHP Tutorial > php怎么按另外一个数组重新排列自身

php怎么按另外一个数组重新排列自身

WBOY
Release: 2016-06-13 10:38:17
Original
942 people have browsed it

php如何按另外一个数组重新排列自身?
php如何按另外一个数组重新排列自身?


------解决方案--------------------

PHP code
function array_order(&$ar, $by) {  asort($by);  foreach($by as $k=>$v) {    $r[$k] = $ar[$k];  }  return $ar = $r;}$arr = array(  'a' => 'aa',  'b' => 'bb',  'c' => 'cc',);$sort_by = array(  'a' => 2,  'b' => 3,  'c' => 1,);array_order($arr, $sort_by);print_r($arr);<br><font color="#e78608">------解决方案--------------------</font><br>array_multisort($sort_by,SORT_ASC,$arr);<br>print_r($arr);<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template