/ Published in: PHP
I needed to trim a simple numerical array that might have duplicate values into an array with no duplicates. I came up with this before finding array_unique(). D\'oh.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php function returnValueOnce($array){ //array_count_values returns an array( [1]=>3 [2]=> 4 [3]=> 1 ) return $arrayTrim; //returns numerical array(1,2,3) } // the array_unique() function does this too, so now I'm the wiser.... // it removes duplicate values from an array. If two or more array values are the same, the // first appearance will be kept and the other will be removed. ?>
URL: http://www.w3schools.com/php/func_array_unique.asp