0
PHP array_unique function not working
LEGEND
,
/t5/dreamweaver-discussions/php-array-unique-function-not-working/td-p/566604
Jun 26, 2006
Jun 26, 2006
Copy link to clipboard
Copied
hi:
i have a table in a MySQL DB containing a field named E_YEAR, type
year(4). i loop through all records storing years in an array:
$e_years = array();
...
(loop)
$e_years[$i] = $row_rsExhib['E_YEAR'];
...
(end loop)
as E_YEAR field has duplicated values i've used the array_unique
function to show only unique ones but no way it do the job, just shows
the first although the array has 4 values afeter array_unique
echo count($e_years).'-';
$e_years = array_unique($e_years);
echo count($e_years).'-';
for ($i=0; $i<count($e_years); $i++) {
echo $e_years[$i].'-';
}
output: 20-4-2003----
if i comment the second line this is the output;
20-20-2003-2003-2003-2003-2003-2004-2004-2004-2004-2004-2004-2005-2005-2005-2005-2005-2006-2006-2006-2006
surely i'm missing something obvious but can't find what it is
tia,
jdoe
i have a table in a MySQL DB containing a field named E_YEAR, type
year(4). i loop through all records storing years in an array:
$e_years = array();
...
(loop)
$e_years[$i] = $row_rsExhib['E_YEAR'];
...
(end loop)
as E_YEAR field has duplicated values i've used the array_unique
function to show only unique ones but no way it do the job, just shows
the first although the array has 4 values afeter array_unique
echo count($e_years).'-';
$e_years = array_unique($e_years);
echo count($e_years).'-';
for ($i=0; $i<count($e_years); $i++) {
echo $e_years[$i].'-';
}
output: 20-4-2003----
if i comment the second line this is the output;
20-20-2003-2003-2003-2003-2003-2004-2004-2004-2004-2004-2004-2005-2005-2005-2005-2005-2006-2006-2006-2006
surely i'm missing something obvious but can't find what it is
tia,
jdoe
TOPICS
Server side applications
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Newsgroup_User
AUTHOR
LEGEND
,
LATEST
/t5/dreamweaver-discussions/php-array-unique-function-not-working/m-p/566605#M151036
Jun 26, 2006
Jun 26, 2006
Copy link to clipboard
Copied
forced by the time i had to use a nasty workaround:
$y = implode(",", array_unique($e_years));
$e_years = explode(",", $y);
for ($i=0; $i<count($e_years); $i++) {
echo '<DIV class="years">'.$e_years[$i].'</DIV>';
}
someone can bring this to light?
tia,
jdoe
John Doe wrote:
> hi:
>
> i have a table in a MySQL DB containing a field named E_YEAR, type
> year(4). i loop through all records storing years in an array:
>
> $e_years = array();
> ...
> (loop)
> $e_years[$i] = $row_rsExhib['E_YEAR'];
> ...
> (end loop)
>
>
> as E_YEAR field has duplicated values i've used the array_unique
> function to show only unique ones but no way it do the job, just shows
> the first although the array has 4 values afeter array_unique
>
> echo count($e_years).'-';
> $e_years = array_unique($e_years);
> echo count($e_years).'-';
> for ($i=0; $i<count($e_years); $i++) {
> echo $e_years[$i].'-';
> }
>
> output: 20-4-2003----
>
> if i comment the second line this is the output;
>
> 20-20-2003-2003-2003-2003-2003-2004-2004-2004-2004-2004-2004-2005-2005-2005-2005-2005-2006-2006-2006-2006
>
>
> surely i'm missing something obvious but can't find what it is
>
> tia,
>
> jdoe
$y = implode(",", array_unique($e_years));
$e_years = explode(",", $y);
for ($i=0; $i<count($e_years); $i++) {
echo '<DIV class="years">'.$e_years[$i].'</DIV>';
}
someone can bring this to light?
tia,
jdoe
John Doe wrote:
> hi:
>
> i have a table in a MySQL DB containing a field named E_YEAR, type
> year(4). i loop through all records storing years in an array:
>
> $e_years = array();
> ...
> (loop)
> $e_years[$i] = $row_rsExhib['E_YEAR'];
> ...
> (end loop)
>
>
> as E_YEAR field has duplicated values i've used the array_unique
> function to show only unique ones but no way it do the job, just shows
> the first although the array has 4 values afeter array_unique
>
> echo count($e_years).'-';
> $e_years = array_unique($e_years);
> echo count($e_years).'-';
> for ($i=0; $i<count($e_years); $i++) {
> echo $e_years[$i].'-';
> }
>
> output: 20-4-2003----
>
> if i comment the second line this is the output;
>
> 20-20-2003-2003-2003-2003-2003-2004-2004-2004-2004-2004-2004-2005-2005-2005-2005-2005-2006-2006-2006-2006
>
>
> surely i'm missing something obvious but can't find what it is
>
> tia,
>
> jdoe
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

