|
-
Jul 14th, 2009, 09:31 AM
#1
Thread Starter
Addicted Member
[RESOLVED] remove a [key] from array
How can I remove a key eg [2] from an array
[2] => A [4] => B [6] => C ??
-
Jul 14th, 2009, 02:37 PM
#2
Re: remove a [key] from array
use unset()?
PHP Code:
unset($array[2]);
-
Jul 15th, 2009, 05:46 AM
#3
Thread Starter
Addicted Member
Re: remove a [key] from array
Just what I'm after 
Thanks
-
Jul 24th, 2009, 04:32 AM
#4
Thread Starter
Addicted Member
Re: [RESOLVED] remove a [key] from array
I have this code...
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; ?>
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?
-
Jul 24th, 2009, 04:41 AM
#5
Re: [RESOLVED] remove a [key] from array
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.
Code:
<input type="hidden" name="items[]" value="whatever" />
using 5 of these should produce the keys 0 through 4.
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.
-
Jul 27th, 2009, 02:21 AM
#6
Thread Starter
Addicted Member
Re: [RESOLVED] remove a [key] from array
Doh, you make it sound so simple...
'if $key is above $deleterow, then $key is equal to $key minus 1'
Thanks
-
Aug 2nd, 2009, 11:57 PM
#7
Re: [RESOLVED] remove a [key] from array
 Originally Posted by kows
let the browser/server figure out what keys to use.
Server... The browser simply sends the key/value pairs without regard to their keys or values. The PHP interpreter creates an array when it receives keys with the empty bracket pair.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|