Delete An Item From An Index Array?
How can I delete an Item from an index array in php4?
View Complete Forum Thread with Replies
Related Forum Messages:
Completely Delete A Specific Array Index
I was wondering if anyone could tell me if there is a way to completely delete a specific array index once it has been set. For instance, I have an array with 50 indexes (0 - 49) sizeof = 50. Now, I want to eliminate 10 indexes, making my array sizeof 40 and having array indexes 0-39.
View Replies !
Index Of Inserted Item
is there an easy way of getting the index of a INSERT command? I have an auto-increment field in DB and have just inserted a record and need to know what the value of that auto-increment is.
View Replies !
Delete Item From Database
I still can't figure out how to delete an item from my shoppingcart. I have tried different ways to do this, but its impossible. -a button or link that deletes a item from my database -the php script that deletes it here is a suggestion: $slett = "DELETE ID, VARE, MODELL, STR, ANTALL, PRIS, TOTALPRIS FROM USER_TRACK WHERE USER_ID = "$user_id""; But how can i assign this to a button?
View Replies !
Listing Table Data With An Option To Delete Each Individual Item.
Was wondering if anyone could help me with a PHP, MySQL problem. I am completely new to PHP and MySQL. I have been trying to find a way to list data from a table on a web page and after each individual item have a hyperlink to allow users to delete the information listed. Can anyone help? i.e. Name Age Sex ------------------------------------------ Adam 21 M delete Betty 22 F delete Chris 23 M delete Daisy 24 F delete ------------------------------------------------------------------------------------------------------------------------------ (delete after 'Sex' would be the hyperlink to delete that entire line (row) from the table).
View Replies !
Array Explode Problem Result In A 6 Item Array
I have the following: $BB_Basket = "basket=¦APL6007,2.00¦AVX8900,1.00¦ARCAV500,1.00"; $basket_containers = explode('¦', $BB_Basket); unset($basket_containers[0]); print_r($basket_containers); This results in Array ( [1] => APL6007,2.00 [2] => AVX8900,1.00 [3] => ARCAV500,1.00 ) Now when I try to explode further with $basket_items = explode(',', $basket_containers); print_r($basket_items); This results in Array ( [0] => Array ) This should result in a 6 item array. Any ideas what I'm doing wrong?
View Replies !
Item In Array
I have an array, set up like this: $this->navigation_array['Home'] = array('text' => 'Home', 'act' => 'Home', 'redirect' => 'No', 'active' => 'Home', 'link' => 'index.php?act=home', 'default' => 'Info'); $this->navigation_array['Forums'] = array('text' => 'Forums', 'act' => 'Forums', 'redirect' => 'No', 'active' => 'Forums', 'link' => 'index.php?act=forums', 'default' => 'Info'); $this->navigation_array['Users'] = array('text' => 'Users', 'act' => 'Users', 'redirect' => 'No', 'active' => 'Users', 'link' => 'index.php?act=users'); $this->navigation_array['Config'] = array('text' => 'Configuration', 'act' => 'Config', 'redirect' => 'No', 'active' => 'Config', 'link' => 'index.php?act=config'); I want to find the first item inserted into the array, namely "Home". What is the fastest way to just call the first entry? You cant use $this->navigation_array[0] in this case because the keys are text not numbers.
View Replies !
Deleting An Array Item
I have a standard array: $foo = array( 0 => 'abc' 1 => 'def' 2 => 'ghi'); and I have a variable, $bar, which equals 'def' ... and I want to check my array to see if the value of $bar exists in the array, and if it does, delete it from the array. if (in_array($bar, $foo)) { // what goes here??? } I've done this before, but for the life of me, I'm drawing a blank now. Help a bruthah out?
View Replies !
Random Item Of An Array
What is the best way of picking out a random item of an array, regarding speed and CPU-usage ? I need a super fast way of picking out an ID from my MySQL db.
View Replies !
Modify Array Item
I'm building a shopping cart and need to add the function so if an item is selected twice, the 'quantity' counter increments. I can't get the syntax right for modifying the array value. I have this: foreach ($_SESSION['basket'] as $key => $row) { if ( $row['gnsz']==$gnsz) { $newqty=$row['qty'] ; $newqty++; $row['qty']= $newqty; } } it picks up the first qty value but I can't seem to modify it in the array. I'm making a dumb mistake somewhere .
View Replies !
Put The Itemid Of An Item Into An Array.
$count = 1; foreach($trade as $val) { $val = checkinput($val); $sel=mysql_query("SELECT * FROM `inventory` WHERE `ID` = '$val' AND `userid` = '$userid2'") or die(mysql_error()); $n=mysql_num_rows($sel); if($n == 0) { $input = "You do not own this item."; error($input); } $g=mysql_fetch_array($sel); $itemid = $g['itemid']; $itemid[$count] = $itemid; $count++; } Basically, my script is trying to put the itemid of an item into an array. The problem i'm getting is that, it's not saving the values in the array. For example, if i have 3 items and it puts them into the array, it will only save the 3rd item in the array $itemid[3] and 1 and 2 will be blank.
View Replies !
Current Item From An Array
i have an include file with many arrays that look like this: Code: $event[] = array ('stuff' => 'bla'); $times[] = mktime(0,0,0,6,9,2007); as of right now, I am using asort to sort all of these by date and display them as a list.
View Replies !
Find Item In Array
I have the following array $array = array('k1' => 'v1','k2' => 'v2','k3' => 'v3','k4' => 'v4'); how do i select the value that is provided BEFORE the key i provide ex: $mykey = "k2"; $array = array('k1' => 'v1','k2' => 'v2','k3' => 'v3','k4' => 'v4'); $value = somefunctions(); // gives the value v1 ex: $mykey = "k4"; $array = array('k1' => 'v1','k2' => 'v2','k3' => 'v3','k4' => 'v4'); $value = somefunctions(); // gives the value v3.
View Replies !
Item In A Multidimensional Array
I have a multidimensional array (I think). It is an array that has arrays inside it. The inside arrays all have the same structure, (qty, product, color, size). How do I count how many items are 'White' * qty? I looked into the php manual and found array_count_values but others say it doesn't work with MD arrays.:confused: array( [0] array([0]qty, [1]product, [2] color, [3] size) [1] array([0]qty, [1]product, [2] color, [3] size) [2] array([0]qty, [1]product, [2] color, [3] size) [3] array([0]qty, [1]product, [2] color, [3] size) [4] array([0]qty, [1]product, [2] color, [3] size) [5] array([0]qty, [1]product, [2] color, [3] size) [6] array([0]qty, [1]product, [2] color, [3] size) ...)
View Replies !
Extra Item In My Array
Why is my code. $urlarray = explode("/", "/about/new/index.php"); print_r($urlarray); returning this Array ( [0] => [1] => about [2] => new [3] => index.php ). Perhaps I am being dense but why do I have an extra empty value at the beginning of the array. Is there any way I can make it return the ones I want (ie only those containing an actual value) or do I simply have to work around this.
View Replies !
Shopping Cart Item Array
Trying to build a small simple shopping cart and I am having difficulty getting the solution. The cart is displaying each product, but it is overwriting the values. So if I have added 10 products, it shows ten items, but each item has the values of the last product I added. I think that this may be due to me trying to use a key to store both an array and string at once, but Iam not sure. I have looked at other examples but due to different methods, syntax is throwing me off. Code:
View Replies !
Select One Row Of An Array Where Item Number Is ..?
When I call the Ebays XML API I get an array or something similar back (see the code sample), is it possible to "select item_id where item_id = 123123" or something similar as in MySQL? If, How can I do that? Also, I need to attach a PHP variables to the row I selected as for example $starttime, $endtime and so on. Here is the code sample (the end of the scritpt); PHP Code: ....
View Replies !
Retrieving Previous Array Item
I have an array. The array key is the id of the item (for example categories[91], 91 is the ID of the category) all ID are not exactly in date order, but they're added to the array in date order, how do I find the previous (in the sense of when it was added) array entry of, for example category[ྗ']?
View Replies !
Arrays : Returning A Reference To An Array Item ??
I am currently storing a set of objects inside an array, $itemlist = array(); $itemlist[] = new item("myitem"); //... and I am looking to develop a search function, which returns a reference to the found item. function &search_item($itemlist,"myitem") { //... } I am trying to figure out how to obtain a reference to a given item in an array. Indeed, foreach() and each() seem to work on copies of the data in the array. For example: $array = array("a","b","c","d"); print_r($array); foreach($array as $v) $v="xxx"; print_r($array); // $array is unchanged reset($array) ; while(list(,$v)=each($array)) $v="xxx"; print_r($array); // $array is unchanged, again
View Replies !
Deleting A Single Item From The Middle Of An Array?
I have an array that contain objects, I want to be able to test against the id of that object and remove it from the array. In it's simplest for I want to go from this: $people = array('Tom', 'Dick', 'Harriet', 'Brenda', 'Jo'); ...to this... $people = array('Tom', 'Dick', 'Brenda', 'Jo'); The fact that the items in the array are objects should not matter right? Plus I've already written my loops and conditionals to check which item i need to remove. function removeItem ( $item ) { $len = count ( $_SESSION['basket_arr'] ) ; if ( $len == 1 ) { emptyBasket ( ) ; } else { for ( $i = 0 ; $i < $len ; $i++ ) { if ( $item->id == $_SESSION['basket_arr'][$i]->id ) { //$_SESSION['basket_arr'][$i] must go } } }}
View Replies !
Index Of Array
I uses the function in_array to find out if a specified word appears in a specified array, if it is there I want to get the index of this word in the array. So I can use this index to set a value in array2, at the same index. Jeg bruker in_array for å sjekke om et bestemt ord finnes i en bestemt array, hvis det finnes vil jeg få hentet ut indeksen dette ordet har i array'en. Så vil jeg legge inn et tall i en annen array på samme index som ordet. if (in_array($word, $array1)) { $i = index_of_word($array); $array2[$i] = $number_to_put_in_same_index_as_the_word_in_array1; }
View Replies !
Renumber Array Index
Is it possible that I can renumber array indexes? The problem is that I am using array_unique, but it is returning something like this: [1]->value1,[3]->value2,[5]->value3 How can I reset the numbering, so the indexes are 1,2,3 (using a function would be preferable).
View Replies !
Sort Array Without Index
I'd like to sort a multidimensional array that hasn't numerical index, in fact it is like: Array ( [mobile] => Array ( [name_str] => mobile [relationCount_int] => 1 ) [video] => Array ( [name_str] => video [relationCount_int] => 2 ) [flash] => Array ( [name_str] => flash [relationCount_int] => 1 ) [tool] => Array ( [name_str] => tool [relationCount_int] => 1 ) ) And I'd like to sort, for instance for the value of "relationCount_int", so the new order should be something like: Array ( [video] => Array ( [name_str] => video [relationCount_int] => 2 ) [mobile] => Array ( [name_str] => mobile [relationCount_int] => 1 ) [flash] => Array ( [name_str] => flash [relationCount_int] => 1 ) [tool] => Array ( [name_str] => tool [relationCount_int] => 1 ) )
View Replies !
Array Index Question
I have source information in a file, and (part of) this information comes as coordinates. A coordinate consists of a letter followed by a number, ranging from a1 to i9 I'd like to count the number of occurrences of each coordinate, and put them in a matrix. The matrix should look like this (metasyntax): matrix = array ['a'..'i'][1..9] Later on in the script I'd like to be able to refer to a cell in the matrix by using the same letter/number combo. I know I can define an array using strings as keys, but how can I define a..i as keys without the need to specify them all individually?
View Replies !
Quotes Around Array Index?
I have a question about quoting array indices. This is from Rasmus Lerdorf's Programming PHP: Quote: You don't have to quote single-word strings. For instance, $age['Fred'] is the same as $age[Fred]. However, it's considered good PHP style to always use quotes, because quoteless keys are indistinguishable from constants. When you use a constant as an unquoted index, PHP uses the value of the constant as the index: Code:
View Replies !
Printing An Array Using An Index?
I have to print an ACH file from an array I will recieve. I recieve this array through a function then I have to print this array to a file called "ACH.txt". The ACH file is broken down like this. position 01-017 is 1st record to be printed position 018-30 is 2nd record to be printed position 31-44 is 3rd record to be printed etc. I was thinking psuedo code like this Code:
View Replies !
Array Index Problem
im building a shopping cart, and im having the following problem. the array in the bottom is the way i store customer's product and quantity. For example, refer to below, product 3's quantity is 2. $item['product1'] = 1; $item['product2'] = 4; $item['product3'] = 2; $item['product4'] = 1; the problem im having is, how am i suppose to display the product? is it any function to list out the array index? i tried print_r, it did list out, but, it isnt the thing i want... i want an output like the following so that i can use the product id to retrieve the product information from database... product1 : 1 product2 : 4 product3 : 2 product4 : 1
View Replies !
3d Array Index Not Found
Why doesn't this work? PHP Code: $i = 3; foreach($contact as $key => $val) { if($val['name'] == 'tom'){ echo $val['name']; // Tom echo $val['email'][$i] //DOESN"T PRINT tom@foo3.bar echo $val['email'][4]; //tom4@foo.bar ...
View Replies !
Undefined Index In Array
BACKGROUND: Create data arrays for graph plots WHAT WORKS: The SQL portion, the creation of master array-> from which I chose data array per unique category: Code:
View Replies !
Accessing The Last Index Of An Array
for example, i have the following array: $p = "hello.html.c"; $p1 = explode('.', $p); now, if i want to access the extension (c, or index 2 in this case), i would have to do $p1[sizeof($p1) - 1]. I'm used to in python's list just doing p[-1] to accessing elements from the back. I was wondering if there is a similarly easy way of doing this in php.
View Replies !
How Can I Swap An Array Index?
lets say I have an array like this... $Array[0] = "Apples" $Array[1] = "Oranges" $Array[2] = "Grapes" $Array[3] = "Pears" What I want to do is swap the index of "0" with the index of "2" so that my array will look like this. $Array[0] = "Grapes" $Array[1] = "Oranges" $Array[2] = "Apples" $Array[3] = "Pears" *The changes are noted in BOLD* How can I do this?
View Replies !
Find Current Index Value In Array
I am looking for a way to find the numerical index of an array item without coding in a manual count using a foreach. Here is the situation: I am throwing a class a configuration array, where all of the arrays will have the same number of items as follows: PHP Code:
View Replies !
Back Referencing To Get An Array Index?
My website needs to allow users to specify where a thumbnail image will appear in the text ($articleText) they submit. The thumbnail filenames are held in a single-dimensional array called $photos e.g. the users are to type [thumb4] to specify they want thumbnail four ( from array position 4 ) I was hoping the following expression would work, but it doesn't. The returned text always includes <img src="thumbs/"> i.e. no image filename is inserted. (I was expecting something like <img src="thumbs/dave.jpg"> ) $articleText = preg_replace("/[thumb(d+)]/", "<img src="thumbs/".$photos[$1]."">", $articleText);
View Replies !
Undefined Array Index Question
I am curious about how php deals with the following situation where I use an undefined index into an array. PHP seems to be behaving exactly how I want it to but I want to make sure that it is not a fluke. It seems like most programming languages would crash if you used an undefined index. Why does PHP work the way it does? My example is below ....
View Replies !
Retrieve The Index Number Of The Element Of An Array
After some looking around - and maybe entering just the wrong keywords in Google :) - a short question: is it possible to retrieve the index number of the element of an array, let say that there is an array $myArray = ("John", "Tom", "Dick","Harry","Peter") I am looking for a function that tells me that Harry is the fourth element. (I have tried in google things like "retrieve index array php" but without result)
View Replies !
Accessing Numerical Array Index In Foreach
I have no trouble looping through an array using foreach. To keep track of the index, I set a variable before the loop and increment it in the loop: $index = 0; foreach ($array as $item) { blah; $index++; do something that requires knowing the index of the current item; } Is there a better way to access that index value?
View Replies !
Getting A (non-radio) Button's Index Number From Array
If you could assist me with the following situation, I have a table of data retrieved from database displayed on screen. To each row of data, I have added action buttons, such as "Edit", "Add", and "Comment". Since I do not know how many rows of data will be retrieved - and therefore how many buttons I need - I am using button arrays for each button, like so: echo "<input type="submit" value="Comment" name="Comment[]" />"; In the php file that processes the input from this form, I have the following code, which I was under the impression would give me the index in the Comment array of the button that was fired. if (isset($_POST['CommentMedicalHistory'])) { $indexOfComment = each($_POST['CommentMedicalHistory']); echo "index = {$indexOfComment['key']}"; } Unfortunately, it is returning 0 as the index all the time, even when I do not click on the Comment button in the first row. Do you know by any chance how I could get the correct index of the button that was pressed from the array?
View Replies !
Structure The Data In Column That Should Be Index Of Array
MySQL Table structure. ID name value 1 c01 abc 2 c01 def 3 c02 xyz Here i want to structure the data in such a way that name column should be index of array and values should be mapped to index for eg. Array( [1] => Array ( [c01] => array([0] => abc [1] => def [2] => Array ( [c02] => array([0] => xyz .
View Replies !
|