PHP简单实现多维数组合并与排序功能示例

yipeiwu_com7年前PHP代码库

本文实例讲述了PHP简单实现多维数组合并与排序功能。分享给大家供大家参考,具体如下:

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

运行结果:

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

更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《php常用函数与技巧总结》、《PHP错误与异常处理方法总结》、《PHP基本语法入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

相关文章

PHP生成UTF8文件的方法

复制代码 代码如下:<?php $f=fopen("test.txt", "wb"); $text=utf8_encode("a!"); //先用函数utf8_encode将所需写...

解决file_get_contents无法请求https连接的方法

错误: Warning: fopen() [function.fopen]: Unable to find the wrapper "https" - did you forget to...

PHP JS Ip地址及域名格式检测代码

PHP IP地址格式检测函数 复制代码 代码如下:function checkIp($ip){    $ip = str_replace(" ", "",...

php 多关键字 高亮显示实现代码

php 多关键字 高亮显示实现代码

项目结构: 开始搜索:   这里搜索关键字("大""这") 搜索结果:  高亮显示 项目所需数据库结构: 实现代码: conn.php 复制代码 代码...

基于php split()函数的用法详解

PHP函数split()的基本语法为:array split ( string $pattern, string $string [, int $limit] )。我们向大家举了两个例子...