note 49627 modified in function.array-unique by danbrown

From: Date: Thu, 06 Nov 2008 15:08:34 +0000
Subject: note 49627 modified in function.array-unique by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-146232@lists.php.net to get a copy of this message
Just a simple implementation for JavaScript: <?php function array_unique(thearray) { thearray.sort(); //reset($thearray); newarray = new Array(); for (n=0;n<thearray.length;n++) { unique=1;//by default for(nn=0;nn<newarray.length;nn++) if (thearray[n] == newarray[nn]) { unique=0;//already exists break; } if(unique)//dont exists newarray.push(thearray[n]); } return newarray; } ?> --was-- Just a simple implementation for JavaScript: function array_unique(thearray) { thearray.sort(); //reset($thearray); newarray = new Array(); for (n=0;n<thearray.length;n++) { unique=1;//by default for(nn=0;nn<newarray.length;nn++) if (thearray[n] == newarray[nn]) { unique=0;//already exists break; } if(unique)//dont exists newarray.push(thearray[n]); } return newarray; } http://php.net/manual/en/function.array-unique.php

« previous php.notes (#146232) next »