Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Troubles with array_unique() function.

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi.
I have troubles with array_unique() function. It must to take input array and to return a new array without duplicate values.
In one part of my program I need to clear duplicate values from two dimensional array consist only digits. This is small example of program:
$digits= array( array( "value1"=>1,"value2"=>5,"value3"=>7),
array( "value1"=>3,"value2"=>6,"value3"=>10),
array( "value1"=>1,"value2"=>5,"value3"=>7),
array( "value1"=>14,"value2"=>17,"value3"=>3),
array( "value1"=>1,"value2"=>5,"value3"=>7),
);

for ($i=0;$i<5;$i++)
echo &quot;|&quot;.$digits[$i][&quot;value1&quot;].&quot;|&quot;.$digits[$i][&quot;value2&quot;].&quot;|&quot;.$digits[$i][&quot;value3&quot;].&quot;|<br>&quot;;

echo &quot;Here must see distinct rows.<br>&quot;;

$distinct_digits=array_unique($digits);
for ($j=0;$j<5;$j++)
echo &quot;|&quot;.$distinct_digits[$j][&quot;value1&quot;].&quot;|&quot;.$distinct_digits[$j][&quot;value2&quot;].&quot;|&quot;.$distinct_digits[$j][&quot;value3&quot;].&quot;|<br>&quot;;

The output of this program is:
|1|5|7|
|3|6|10|
|1|5|7|
|14|17|3|
|1|5|7|
Here must see distinct rows.
||||
|3|6|10|
||||
||||
||||


I expect to receive this:
|1|5|7|
|3|6|10|
|1|5|7|
|14|17|3|
|1|5|7|
Here must see distinct rows.
|1|5|7|
|3|6|10|
||||
|14|17|3|
||||
This code working by expected from me way in php ver.4.0.4pl1 but not in ver 4.1.2 .

Can somebody help me with this problem?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top