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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 13:19:17
Original
946 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
Latest Issues
How to create an array within an array?
From 1970-01-01 08:00:00
0
0
0
php array
From 1970-01-01 08:00:00
0
0
0
Array to array
From 1970-01-01 08:00:00
0
0
0
php array rotation
From 1970-01-01 08:00:00
0
0
0
array
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template