4
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【PHP】多次元配列の重複削除

Last updated at Posted at 2015-01-29

こういうデータがあったとして

[
  [
    "pit",
    "28"
    "id011"
  ],
  [
    "john",
    "34",
    "id023"
  ],
  [
    "bob",
    "24",
    "id011"
  ],
  [
    "marry",
    "23",
    "id032"
  ]
]

例えば「同じIDだったら除外したい」という場合とかに

 $tmp = array();
 $array_result = array();
 
 foreach( $array_org as $key => $value ){
 
  // 配列に値が見つからなければ$tmpに格納
  if( !in_array( $value['id'], $tmp ) ) {
   $tmp[] = $value['id'];
   $array_result[] = $value;
  }

 }
 $data = $array_result;
4
9
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?