Im a beginner in PHP and Im having a problem with this code. Im
trying to remove duplicate elements from an array created via $_GET.
I want users to be able to click on a link which sends an email
address to an array. I just want to remove duplicate email addresses
from the array. Ive tried array_unique() on my test server but it
doesnt work. So i tried to remove duplicates myself before storing
them into the array. The script works great without the checking, but
I cant have duplicate emails in the array...please help!
session_start();
$email = $HTTP_GET_VARS['email'];
if (isset($_SESSION['Array']))
{
$Array = $_SESSION['Array'];
$numElements = count($Array);
for($counter=0; $counter < $numElements; $counter++)
{
/* Problem is here */ if ($Array[$counter] == $email)
{
exit();
}
else
{
array_push($_SESSION['Array'],$email);
$EmailArray = $_SESSION['Array'];
$_SESSION['Array'] = $EmailArray;
}
}
}
else
{
$EmailArray = array();
array_push($EmailArray,$email);
$_SESSION['Array'] = $EmailArray;
}