Created
July 12, 2014 09:43
-
-
Save Khanashima/53d23b31f1cf9fb399d2 to your computer and use it in GitHub Desktop.
array_unique()で値の重複は削除できるけど、キーが飛び飛びになる。array_values()で解決 ref: http://qiita.com/kiimiiis/items/c39aea90b653f8b5f5cf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//テスト配列 | |
$array = array('test1', 'test2', 'test1', 'test3', 'test2', 'test'); | |
//配列で重複している物を削除する | |
$unique = array_unique($array); | |
//キーが飛び飛びになっているので、キーを振り直す | |
$alignedUnique = array_values($unique); | |
?> | |
<?php echo("<pre>"); ?> | |
<div> | |
<p>・テスト配列</p> | |
<?php var_dump($array); ?> | |
</div> | |
<div> | |
<p>・重複を削除しただけの配列</p> | |
<?php var_dump($unique); ?> | |
</div> | |
<div> | |
<p>・キーを振りなおした配列</p> | |
<?php var_dump($alignedUnique); ?> | |
</div> | |
<?php echo("</pre>"); ?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment