problem with function array_* that preserved the key
| From: | Reuben D Budiardja | Date: | Sat, 03 Nov 2001 20:54:23 +0000 |
| Subject: | problem with function array_* that preserved the key | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-73355@lists.php.net to get a copy of this message | ||
Hi,
I have problem with array function that return an array and preserved the key
of the array argument. Take example of array_diff:
I have 2 arrays that has index 0,1,2, ... as the key, and use it as the
argument, say $arrA, and $arrB,
$arrC = array_diff($arrA, $arrB);
since the key are preserved, arrC is no longer indexed from 0. Well, in most
cases I don't care about the key if it's just indexed array. But since the
key I preserved, I can no longer do
for($i=0; $i<count($arrC);$i++)
echo $arrC[$i];
if it happens that the returned indedex in array C 19, 20,25, for example.
Any workaround?
Thanks.
Reuben D. Budiardja