note 70273 modified in function.array-unique by danbrown

From: Date: Thu, 06 Nov 2008 14:58:18 +0000
Subject: note 70273 modified in function.array-unique by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-146221@lists.php.net to get a copy of this message
Here's the shortest line of code I could find/create to remove all duplicate entries from an array and then reindex the keys. <?php // Fruits, vegetables, and other food: $var = array('apple','banana','carrot','cat','dog','egg','eggplant','fish'); $var = array_values(array_unique($var)); ?> --was-- Here's the shortest line of code I could find/create to remove all duplicate entries from an array and then reindex the keys. //$var is an array. This example its one-dimensional. Your most basic kind of array. $var = array_values(array_unique($var)); http://php.net/manual/en/function.array-unique.php

« previous php.notes (#146221) next »