Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

PHP array_unique function not working

LEGEND ,
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
TOPICS
Server side applications

Views

812
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 26, 2006 Jun 26, 2006

Copy link to clipboard

Copied

LATEST
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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines