数组对象去除重复的值
Array( [4968] => WP_Post Object ( [ID] => 4968 [post_author] => 1 [post_date] => 2013-11-30 14:32:54 [post_date_gmt] => 2013-11-30 06:32:54 [post_content] => [post_title] => taibei [post_excerpt] => 来到台北的日子 [post_status] => inherit [comment_status] => open [ping_status] => open [post_password] => [post_name] => taibei [to_ping] => [pinged] => [post_modified] => 2013-11-30 14:32:54 [post_modified_gmt] => 2013-11-30 06:32:54 [post_content_filtered] => [post_parent] => 4058 [guid] => http://tanteng-wordpress.stor.sinaapp.com/uploads/2013/01/taibei.jpg [menu_order] => 0 [post_type] => attachment [post_mime_type] => image/jpeg [comment_count] => 0 [filter] => raw ) [4951] => WP_Post Object ( [ID] => 4951 [post_author] => 1 [post_date] => 2013-11-29 14:38:33 [post_date_gmt] => 2013-11-29 06:38:33 [post_content] => [post_title] => taipei [post_excerpt] => 台北路的生活 [post_status] => inherit [comment_status] => open [ping_status] => open [post_password] => [post_name] => taipei-3 [to_ping] => [pinged] => [post_modified] => 2013-11-29 14:38:33 [post_modified_gmt] => 2013-11-29 06:38:33 [post_content_filtered] => [post_parent] => 4058 [guid] => http://tanteng-wordpress.stor.sinaapp.com/uploads/2013/01/taipei.jpgpsid1 [menu_order] => 0 [post_type] => attachment [post_mime_type] => image/jpeg [comment_count] => 0 [filter] => raw ) [4940] => WP_Post Object ( [ID] => 4940 [post_author] => 1 [post_date] => 2013-11-28 12:53:08 [post_date_gmt] => 2013-11-28 04:53:08 [post_content] => [post_title] => 201304181305293855 [post_excerpt] => [post_status] => inherit [comment_status] => open [ping_status] => open [post_password] => [post_name] => 201304181305293855 [to_ping] => [pinged] => [post_modified] => 2013-11-28 12:53:08 [post_modified_gmt] => 2013-11-28 04:53:08 [post_content_filtered] => [post_parent] => 4509 [guid] => http://tanteng-wordpress.stor.sinaapp.com/uploads/2013/09/201304181305293855.pngpsid1 [menu_order] => 0 [post_type] => attachment [post_mime_type] => image/png [comment_count] => 0 [filter] => raw ) [4937] => WP_Post Object ( [ID] => 4937 [post_author] => 1 [post_date] => 2013-11-28 09:55:07 [post_date_gmt] => 2013-11-28 01:55:07 [post_content] => [post_title] => wordpress-custom-query-string [post_excerpt] => [post_status] => inherit [comment_status] => open [ping_status] => open [post_password] => [post_name] => wordpress-custom-query-string [to_ping] => [pinged] => [post_modified] => 2013-11-28 09:55:07 [post_modified_gmt] => 2013-11-28 01:55:07 [post_content_filtered] => [post_parent] => 4936 [guid] => http://tanteng-wordpress.stor.sinaapp.com/uploads/2013/11/wordpress-custom-query-string.jpg [menu_order] => 0 [post_type] => attachment [post_mime_type] => image/jpeg [comment_count] => 0 [filter] => raw ) [4931] => WP_Post Object ( [ID] => 4931 [post_author] => 1 [post_date] => 2013-11-27 10:41:47 [post_date_gmt] => 2013-11-27 02:41:47 [post_content] => [post_title] => yming [post_excerpt] => [post_status] => inherit [comment_status] => open [ping_status] => open [post_password] => [post_name] => psb-1 [to_ping] => [pinged] => [post_modified] => 2013-11-27 10:41:47 [post_modified_gmt] => 2013-11-27 02:41:47 [post_content_filtered] => [post_parent] => 0 [guid] => http://tanteng-wordpress.stor.sinaapp.com/uploads/2013/11/psb-1.jpg [menu_order] => 0 [post_type] => attachment [post_mime_type] => image/jpeg [comment_count] => 0 [filter] => raw ))
我得到一个这样的对象数组,每个数组里面的对象的键要保留,但是post_parent的值相同的,只保留第一个,怎么写函数???
回复讨论(解决方案)
$st = array();foreach($ar as $i=>$o) { if(in_array($o->post_parent, $st)) unset($ar[$i]); else $st[] = $o->post_parent;}
$st = array();foreach($ar as $i=>$o) { if(in_array($o->post_parent, $st)) unset($ar[$i]); else $st[] = $o->post_parent;}
唠叨!哈哈,才知道哦.
大神,我不明白你的$ar是哪里来的。麻烦解释下被。
而且这个$o->post_partent是不是这个多维数组里的所有post_parent的值啊?
还有您这种写法,我很是迷糊。。您是不是又简写了!
$st = array();foreach($ar as $i=>$o) { if(in_array($o->post_parent, $st)) unset($ar[$i]); else $st[] = $o->post_parent;}
$images =& get_children( 'post_type=attachment&post_mime_type=image&numberposts=5&post_parent=true' ); foreach ($images as $k=>$v){ $temp[$k]=$v->post_parent; } $temp=array_unique($temp); $temp=array_filter($temp); foreach ($temp as $k=>$v){ if(!is_imagetype($v)){ unset($temp[$k]); } }
我是这样写的,跟你的比真是弱爆了!!为了实现首页幻灯的效果,你看看,已经弄好了。
http://www.tantengvip.com/
$st = array();foreach($ar as $i=>$o) { if(in_array($o->post_parent, $st)) unset($ar[$i]); else $st[] = $o->post_parent;}
唠叨!哈哈,才知道哦.
大神,我不明白你的$ar是哪里来的。麻烦解释下被。
而且这个$o->post_partent是不是这个多维数组里的所有post_parent的值啊?
还有您这种写法,我很是迷糊。。您是不是又简写了!
$ar就是我输出的那一段数组对象
楼主的方法显然是想多了,显得太复杂
$arr = array();$comp = array_keys(array_unique(array_column($arr,'post_parent','id')));foreach ($arr as $k=>$v){ if(! in_array($v['id'], $comp)) unset($arr[$k]);}print_r($arr);

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Alipay PHP ...

JWT는 주로 신분증 인증 및 정보 교환을 위해 당사자간에 정보를 안전하게 전송하는 데 사용되는 JSON을 기반으로 한 개방형 표준입니다. 1. JWT는 헤더, 페이로드 및 서명의 세 부분으로 구성됩니다. 2. JWT의 작업 원칙에는 세 가지 단계가 포함됩니다. JWT 생성, JWT 확인 및 Parsing Payload. 3. PHP에서 인증에 JWT를 사용하면 JWT를 생성하고 확인할 수 있으며 사용자 역할 및 권한 정보가 고급 사용에 포함될 수 있습니다. 4. 일반적인 오류에는 서명 검증 실패, 토큰 만료 및 대형 페이로드가 포함됩니다. 디버깅 기술에는 디버깅 도구 및 로깅 사용이 포함됩니다. 5. 성능 최적화 및 모범 사례에는 적절한 시그니처 알고리즘 사용, 타당성 기간 설정 합리적,

PHP 개발에서 견고한 원칙의 적용에는 다음이 포함됩니다. 1. 단일 책임 원칙 (SRP) : 각 클래스는 하나의 기능 만 담당합니다. 2. Open and Close Principle (OCP) : 변경은 수정보다는 확장을 통해 달성됩니다. 3. Lisch의 대체 원칙 (LSP) : 서브 클래스는 프로그램 정확도에 영향을 미치지 않고 기본 클래스를 대체 할 수 있습니다. 4. 인터페이스 격리 원리 (ISP) : 의존성 및 사용되지 않은 방법을 피하기 위해 세밀한 인터페이스를 사용하십시오. 5. 의존성 반전 원리 (DIP) : 높고 낮은 수준의 모듈은 추상화에 의존하며 종속성 주입을 통해 구현됩니다.

시스템이 다시 시작된 후 UnixSocket의 권한을 자동으로 설정하는 방법. 시스템이 다시 시작될 때마다 UnixSocket의 권한을 수정하려면 다음 명령을 실행해야합니다.

기사는 PHP 5.3에 도입 된 PHP의 LSB (Late STATIC BING)에 대해 논의하여 정적 방법의 런타임 해상도가보다 유연한 상속을 요구할 수있게한다. LSB의 실제 응용 프로그램 및 잠재적 성능

PHP 개발에서 PHP의 CURL 라이브러리를 사용하여 JSON 데이터를 보내면 종종 외부 API와 상호 작용해야합니다. 일반적인 방법 중 하나는 컬 라이브러리를 사용하여 게시물을 보내는 것입니다 ...

기사는 입력 유효성 검사, 인증 및 정기 업데이트를 포함한 취약점을 방지하기 위해 프레임 워크의 필수 보안 기능을 논의합니다.

phpstorm에서 CLI 모드를 디버그하는 방법은 무엇입니까? PHPStorm으로 개발할 때 때때로 CLI (Command Line Interface) 모드에서 PHP를 디버그해야합니다 ...
