array_unique関数を使用ã—ã¦ã€ä¸€æ¬¡å…ƒé…列ã®é‡è¤‡é …目を削除ã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ãŒã€ã§ã¯äºŒæ¬¡å…ƒé…列ã®å ´åˆã¯ã©ã†ã™ã‚‹ã®ã§ã—ょã†ã‹ã€‚マニュアルã®ãƒ¦ãƒ¼ã‚¶ãƒ¼ãƒŽãƒ¼ãƒˆã«ä¾¿åˆ©ãªã‚«ã‚¹ã‚¿ãƒ 関数ãŒã‚¢ãƒƒãƒ—ã•れã¦ã„ã‚‹ã®ã§ä½¿ç”¨ã—ã¦ã¿ãŸã®ã§ã™ãŒã€ã‹ãªã‚Šä½¿ã„ã‚„ã™ã‹ã£ãŸã®ã§ç´¹ä»‹ã—ã¾ã™ã€‚
MoDæ°ã®æŠ•稿をå‚照。
function remove_duplicate($array, $field)
{
foreach ($array as $sub)
$cmp[] = $sub[$field];
$unique = array_unique($cmp);
foreach ($unique as $k => $rien)
$new[] = $array[$k];
return $new;
}
$field ã«ã€ã‚¨ãƒ¬ãƒ¡ãƒ³ãƒˆã®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹åを記入ã—ã¾ã™ã€‚使用例ã¨ã—ã¦ã¯ã€
$arr = array( array( 'title' => 'test01', 'date' => '2006-11-24', 'description' => 'this is a test' ), array( 'title' => 'test02', 'date' => '2006-11-25', 'description' => 'this is another test' ), array( 'title' => 'test03', 'date' => '2006-11-26', 'description' => 'this is a test' ), array( 'title' => 'test01', 'date' => '2006-11-27', 'description' => 'this is a testthis is a different test' ) );
ã¨ã„ã†äºŒæ¬¡å…ƒé…列ãŒã‚ã£ãŸã¨ã—ã¾ã™ã€‚ã“ã®é…列ã¯ãれãžã‚Œ $arr[0][’title’] 㨠$arr[3][’title’] ã€$arr[0][’description’] 㨠$arr[2][’description’] ãŒé‡è¤‡ã—ã¦ã„ã¾ã™ã€‚ã“れを上ã®é–¢æ•°ã‚’使用ã—ã¦ã²ã¨ã¤ã«ã¾ã¨ã‚ã¦ã¿ã¾ã™ã€‚
 
$arr = remove_duplicate($arr, 'title');
ã§ [’title’] ã®é‡è¤‡é …ç›®ãŒå‰Šé™¤ã•れã€çµæžœã€
Array (
[0] => Array ( [title] => test01 [date] => 2006-11-24 [description] => this is a test )
[1] => Array ( [title] => test02 [date] => 2006-11-25 [description] => this is another test )
[2] => Array ( [title] => test03 [date] => 2006-11-26 [description] => this is a test )
)
ã¾ãŸã€
$arr = remove_duplicate($arr, 'description');
ã§ [’description’] 下ã®é‡è¤‡é …ç›®ãŒå‰Šé™¤ã•れã¾ã™ã€‚çµæžœã¯ä»¥ä¸‹ã®ã‚ˆã†ã«ãªã‚Šã¾ã™ã€‚
Array ( [0] => Array ( [title] => test01 [date] => 2006-11-24 [description] => this is a test )
[1] => Array ( [title] => test02 [date] => 2006-11-25 [description] => this is another test )
[2] => Array ( [title] => test01 [date] => 2006-11-27 [description] => this is a testthis is a different test )
)



