note 12794 deleted from function.array-unique by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: mads dot rebsdorf at am-vision dot dk 

----

To unique an array in newer versions of php - i've found this snippet useful:

<?php
// $old[0] = 1
// $old[1] = 1
// $old[2] = 2
// $old[3] = 1
// $old[4] = 2

$new = array();

for($i=0;$i<count($old);++$i){

	if(in_array($old[$i], $new) != "true"){
		$new[] = $old[$i];
	}
}

//$new now contains:
//
//$new[0] = 1
//$new[1] = 2
?>

/mads
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.