0

My array $pids contains integers. For example:
18742
59274
94255
97124
18742
94255
94255

I wrote:

$pid = array_unique($pids);
	
	for($i=0; $i<count($pid); $i++)
		echo $i.' '.$pid[$i].'<br />';

And the output is:
0 18742
1
2
3

What's wrong? Why array_unique() doesn't throw away duplicated values?

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by smantscheff
1

array_unique() keeps the indexes intact. If not specified otherwise, these are ascending integers.
Try this instead:

$pid = array_unique($pids);
foreach( $pid as $key => $value )
  echo "$key: $value<br/>";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.