note 112398 added to function.array-unique
| From: | bx16soupapes at gmail dot com | Date: | Tue, 11 Jun 2013 19:55:23 +0000 |
| Subject: | note 112398 added to function.array-unique | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195134@lists.php.net to get a copy of this message | ||
Another form to make an array unique (manual):
This is my array
Array
(
[0] => Array
(
[0] => 40665
[1] => 40665
[2] => 40665
[3] => 40665
[4] => 40666
[5] => 40666
[6] => 40666
[7] => 40666
[8] => 40667
[9] => 40667
[10] => 40667
[11] => 40667
[12] => 40667
[13] => 40668
[14] => 40668
[15] => 40668
[16] => 40668
[17] => 40668
[18] => 40669
[19] => 40669
[20] => 40670
[21] => 40670
[22] => 40670
[23] => 40670
[24] => 40671
[25] => 40671
[26] => 40671
[27] => 40671
[28] => 40671
)
[1] => Array
(
[0] => 40672
[1] => 40672
[2] => 40672
[3] => 40672
)
)
this is my script:
$anterior = 0;
foreach($item as $array_key => $array_value)
{
echo "<li>$array_key";
echo "<ul>";
foreach($array_value as $xarray_key => $xarray_value){
if($xarray_value != $anterior) {
echo "<li>$xarray_key => $xarray_value";
$item_nuevo[$array_key][] = $xarray_value; // or to use the same key number
$item_nuevo[$array_key][$xarray_key] = $xarray_value;
}
$anterior = $xarray_value;
}
echo "</ul>";
}
result:
0
0 => 40665
4 => 40666
8 => 40667
13 => 40668
18 => 40669
20 => 40670
24 => 40671
1
0 => 40672
saludos desde chile.
----
Server IP: 200.29.231.32
Probable Submitter: 190.209.255.198
----
Manual Page -- http://php.net/manual/en/function.array-unique.php
Edit -- https://master.php.net/note/edit/112398
Del: integrated -- https://master.php.net/note/delete/112398/integrated
Del: useless -- https://master.php.net/note/delete/112398/useless
Del: bad code -- https://master.php.net/note/delete/112398/bad+code
Del: spam -- https://master.php.net/note/delete/112398/spam
Del: non-english -- https://master.php.net/note/delete/112398/non-english
Del: in docs -- https://master.php.net/note/delete/112398/in+docs
Del: other reasons-- https://master.php.net/note/delete/112398
Reject -- https://master.php.net/note/reject/112398
Search -- https://master.php.net/manage/user-notes.php