How can I remove a key eg [2] from an array
[2] => A [4] => B [6] => C ??
Printable View
How can I remove a key eg [2] from an array
[2] => A [4] => B [6] => C ??
use unset()?
PHP Code:unset($array[2]);
Just what I'm after :)
Thanks
I have this code...
the code will remove the value and key but I would like to move everything down so the keys still read in order [1][2][3][4][5] etc. Any ideas on how to adapt the code for this?PHP Code:// $deleteRow is the key number I'm looking to remove.
<?php foreach($itemslist as $key => $value): if($key!=$deleteRow){ ;?>
<input type="hidden" name="items[<?php echo $newkey; ?>]" value="<?php echo $value; ?>" />
<?php }endforeach; ?>
if you don't need to be specific with keys, let the browser/server figure out what keys to use. just like in PHP, you can append an array without knowing the last key.
using 5 of these should produce the keys 0 through 4.Code:<input type="hidden" name="items[]" value="whatever" />
if this solution doesn't work for you, then you might be able to apply some logic like, if $key is above $deleterow, then $key is equal to $key minus 1? but, I don't see too many situations where the above wouldn't work.
Doh, you make it sound so simple...
'if $key is above $deleterow, then $key is equal to $key minus 1'
Thanks :)