Introduction to the implementation method of php multi-dimensional array merging and sorting functions

黄舟
Release: 2023-03-16 07:00:01
Original
1392 people have browsed it

This article mainly introduces the simple implementation of multi-dimensional array merging and sorting functions in PHP, involving PHP array merging, sorting and other related operations as well as the usage skills of array_merge, array_multisort and other functions. Friends in need can refer to this article

The example describes the simple implementation of multi-dimensional array merging and sorting functions in PHP. Share it with everyone for your reference, the details are as follows:


<?php
$record=array(
  &#39;title&#39; =>&#39;这个就是标题,第一个数组&#39;,
  &#39;description&#39; =>&#39;描述内容&#39;,
  &#39;picurl&#39; => &#39;照片的链接&#39;,
  &#39;url&#39; =>&#39;链接&#39;,
  &#39;juli&#39; => 34
);
$record_other=array(
  &#39;title&#39; =>&#39;这个就是标题,第二个数组&#39;,
  &#39;description&#39; =>&#39;描述内容&#39;,
  &#39;picurl&#39; => &#39;照片的链接&#39;,
  &#39;url&#39; =>&#39;链接&#39;,
  &#39;juli&#39; => 14
);
//合并数组
$re=array_merge($record,$record_other);
//升序排列,按照“juli”字段排列
$juli_sort = array();
foreach ($re as $arr2) {
  $juli_sort[] = $arr2[&#39;juli&#39;];
}
array_multisort($juli_sort, SORT_ASC, $re);
var_dump($re);
?>
Copy after login

Running results:


array(5) {
 ["juli"]=>
 int(14)
 ["url"]=>
 string(4) "链接"
 ["description"]=>
 string(8) "描述内容"
 ["picurl"]=>
 string(10) "照片的链接"
 ["title"]=>
 string(24) "这个就是标题,第二个数组"
}
Copy after login

The above is the detailed content of Introduction to the implementation method of php multi-dimensional array merging and sorting functions. For more information, please follow other related articles on the PHP Chinese website!

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