怎么合并数组相同的值
Jun 23, 2016 pm 01:17 PM
求大神指导,我想把数组相同的值合并,原本是这样的
array(5) {
[0] => array(1) {
["id"] => string(1) "2"
}
[1] => array(1) {
["id"] => string(1) "2"
}
[2] => array(1) {
["id"] => string(1) "1"
}
[3] => array(1) {
["id"] => string(1) "1"
}
}
我想要的效果是以下这样的
array(5) {
[0] => array(1) {
["id"] => string(1) "1"
}
[1] => array(1) {
["id"] => string(1) "2"
}
}
回复讨论(解决方案)
$ar = array ( 0 => array ( "id" => "2" ), 1 => array ( "id" => "2" ), 2 => array ( "id" => "1" ), 3 => array ( "id" => "1" ),);$arr = array();foreach($ar as $v){ if(!isset($arr[$v['id']])) $arr[$v['id']] = $v;}ksort($arr);print_r(array_values($arr));

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon
