Dysan Posted November 21, 2007 Share Posted November 21, 2007 Using a Numeric Array, how I add and delete data? Quote Link to comment https://forums.phpfreaks.com/topic/78250-numeric-arrays/ Share on other sites More sharing options...
unidox Posted November 21, 2007 Share Posted November 21, 2007 Manually, or a form that edits the db data Quote Link to comment https://forums.phpfreaks.com/topic/78250-numeric-arrays/#findComment-395968 Share on other sites More sharing options...
Dysan Posted November 21, 2007 Author Share Posted November 21, 2007 I presume manually, please correct me if mistaken. Basically I want to store link's ID (The ID at the end of each link) inside an array, upon a link being clicked (e.g. Link 1 shown below). Then upon another link being clicked (e.g Link 2 shown below), delete the appropriate ID from the array, depending on what ID the link contains? 1) www.website.co.uk/functions.php?action=add&id=1 - Add Item 2) www.website.co.uk/functions.php?action=delete&id=1 - Delete Item Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/78250-numeric-arrays/#findComment-395993 Share on other sites More sharing options...
boushley Posted November 21, 2007 Share Posted November 21, 2007 Well... on the page you could do something like $myArray[$id] = null; Quote Link to comment https://forums.phpfreaks.com/topic/78250-numeric-arrays/#findComment-396002 Share on other sites More sharing options...
Dysan Posted November 21, 2007 Author Share Posted November 21, 2007 What does that do? Can you give me some example code, on how to actually add the id number found at the end of the links, to the array? Quote Link to comment https://forums.phpfreaks.com/topic/78250-numeric-arrays/#findComment-396016 Share on other sites More sharing options...
obsidian Posted November 21, 2007 Share Posted November 21, 2007 There are a number of ways to do things like you're after. Here are a few functions to look at: array_push() array_pop() unset() Something like this script may help, too: <?php header('Content-type: text/plain'); $numbers = array(); // empty for ($i = 1; $i <= 10; $i++) { $numbers[] = $i; } print_r($numbers); unset($numbers[4]); print_r($numbers); array_pop($numbers); print_r($numbers); $new = array(); foreach ($numbers as $k => $v) { if ($k != 3 && $k != 7) { $new[$k] = $v; } } print_r($new); ?> Quote Link to comment https://forums.phpfreaks.com/topic/78250-numeric-arrays/#findComment-396021 Share on other sites More sharing options...
obsidian Posted November 21, 2007 Share Posted November 21, 2007 What does that do? Can you give me some example code, on how to actually add the id number found at the end of the links, to the array? I think what you're wanting is something like this: <?php $id = $_GET['id']; $array = array(1, 2, 3, 4, 5); if ($_GET['action'] == 'add') { $array[] = $id; // ...or... array_push($array, $id); } elseif ($_GET['action'] == 'delete') { $new = array(); foreach ($array as $item) { if ($item != $id) { $new[] = $item; } } $array = $new; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/78250-numeric-arrays/#findComment-396028 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.