note 112398 deleted from function.array-unique by crell

From: Date: Tue, 12 Apr 2022 00:51:31 +0000
Subject: note 112398 deleted from function.array-unique by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218166@lists.php.net to get a copy of this message
Note Submitter: bx16soupapes at gmail dot com ---- 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.

« previous php.notes (#218166) next »