On Thu, 2003-01-02 at 17:24, David Busby wrote:
> List,
> Suppose you have an array in PHP like
>
> $ar = array("a", "b", "c", "d", "e", "f", "g");
>
> Now say you want to remove the 3rd item
>
> unset($ar[2]);
>
> All good? Not really...the array doesn't get shifted down, how could one
> pull that off (or should I spin the array and recreate without the undesired
> values?
>
You could sort it in the example given:
<?php
#arraytest.php
$ar = array( "a", "b", "c", "d", "e", "f", "g");
print_r($ar);
unset($ar[2]);
print_r($ar);
sort($ar);
print_r($ar);
?>
[bhughes@bretsony bin]$ php arraytest.php
X-Powered-By: PHP/4.1.2
Content-type: text/html
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
[6] => g
)
Array
(
[0] => a
[1] => b
[3] => d
[4] => e
[5] => f
[6] => g
)
Array
(
[0] => a
[1] => b
[2] => d
[3] => e
[4] => f
[5] => g
)
[bhughes@bretsony bin]$
Is there some reason you care that you do not have an element with the
key of 2? Remember in php all arrays are associative and not really
numerically indexed.
--
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe
https://listman.redhat.com/mailman/listinfo/redhat-list