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 "|".$digits[$i]["value1"]."|".$digits[$i]["value2"]."|".$digits[$i]["value3"]."|<br>";
echo "Here must see distinct rows.<br>";
$distinct_digits=array_unique($digits);
for ($j=0;$j<5;$j++)
echo "|".$distinct_digits[$j]["value1"]."|".$distinct_digits[$j]["value2"]."|".$distinct_digits[$j]["value3"]."|<br>";
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?
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 "|".$digits[$i]["value1"]."|".$digits[$i]["value2"]."|".$digits[$i]["value3"]."|<br>";
echo "Here must see distinct rows.<br>";
$distinct_digits=array_unique($digits);
for ($j=0;$j<5;$j++)
echo "|".$distinct_digits[$j]["value1"]."|".$distinct_digits[$j]["value2"]."|".$distinct_digits[$j]["value3"]."|<br>";
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?