Remove A Single Item From An Array
I have gathered an array of ID's. I need to go throught the array and find a specific ID and remove it from the array. Because we want to keep that ID. Any suggestion of how to do that.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
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 } } }}
How To Remove Unwanted Words/characters From Database Item
currently i dump some data into our database from another database. now, i found some wierd characters  at the end of each of those items. and there are like 500 items in my database table which has those. is there a way that i can remove it using mysql query to be run in mysql or phpmyadmin something like update * from table where field name item has  and replace it with just blank? hope you could help me with this.
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?
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.
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:
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
Removing Item From Array Then Overwriting File
I have a bookings.txt file which has a list of dates each on a new line, for example: - 21/06/07 22/06/07 29/06/07 25/12/07 01/01/08 I also have a variable $event_dd_mm_yy which I want to remove from this file if found. Code:
Single Array To Multidimensional
I have a string, comma separated, with links and their respective URLs in it. Example: Google,http://www.google.com,Yahoo!,http://www.yahoo.com,WikiPedia,http://www.wikipedia.org etc, etc. i make an array of this with explode( ',', $string ); now what i wonder is how can i turn this array into something like this: $array[0]['name'] = Google $array[0]['url'] = http://www.google.com $array[1]['name'] = Yahoo! $array[1]['url'] = http://www.yahoo.com $array[2]['name'] = WikiPedia $array[2]['url'] = http://www.wikipedia.org I hope/think this is all clear ...
Removing A Single Value From $_SESSION Array.
What I have here is three select boxes one for all the tables in the db, one listing the table columns in that table and a third to collect the table columns selected stored in a session called $_SESSION['collections']. Up to this point all that works beautiful the session stores the selected collections. But heres what I want to be able to do: I want to remove single values from the $_SESSION['collections']. How do I do that? Code:
Remove Array Elements With The Given Value From Array
If I have an array, $myarray, with the elements values like (1, 2, 3, 6, 8, 10). I need a function applies to this $myarray to get rid of the element with certain value such as array_function_i_am_looking_for($myarray, 3) will return $myarray with the values (1, 2, 6, 8, 10). I checked out the array function manual. The closest one is array_filter. And I just need to write a function to compare the value for array_filter.
Select Single Column From Mysql Into Array
Is there a way to select a single column from a mysql database and directly put the results into an arrray? Here is the workaround below, but I would like to elimniate the array_push step: $uids=array(); $res = mysql_db_query("db", 'select uid from tbl;', $link); while ($row = mysql_fetch_row($res)) { array_push ($uids, $row[0]); }
Mailparse_msg_get_structure Returning Single Valued Array
I am writing code to strip out and write key data to a database from incoming e-mail. I am using the mailparse functions to handle the incoming mail. My code pulls in the e-mail fine, but the array returned by the mailparse_msg_get_structure() only has one row. The entire contents of the /var/mail/$user file is being put into one row instead of it being broken apart into individual messages. Here is the code:
Remove From Array.
I have an array: <?php echo'<input type="checkbox" name="itemID[]" value="'.$itmNum.'" />'; ?> There will be more than one of these, and when I check the box I will be able to press "Remove Selected" and it should remove that Item from 3 different arrays. basically what I would like to know, is how can I remove an Item from an array if I know its current position?
Add And Remove From Array
What would be the best way too: 1. Take and remove a value from a array_1. Then update array_1. 2. Add the removed value from array_1 to array_2 I'm doing some google searching and I see a function called array_remval that shows this code. Is that the best approach to removing a value? ....
Remove Form Array
I know there must be a function to do this but I can't seem to find it. If you have an array. array( 'a' => 'Apple', 'b' => 'Blue', 'c' => 'Cat' ) Is there a function to remove 'b' => 'Blue'? Or do I have to take the array apart and rebuild it? I have found functions to remove variable of the end and front of arrays but not one to take one out of the middle. I would have thought there would be one that would allow you to do that if you know the key.
Remove Last Two Characters Of An Array
I have an array which ends with a comma and a space. I want to remove the comma and space at the end, but not between the rest of the words in the array. Below is what I have done. I have a list of floor types and a list of people who can have multiple floor types. I have two tables; table1: floortypes: id (int) and type (varchar): id 1 = carpet, id 2 =linoleum, id 3 = tile, id 4 = wood. table 2: listings: id (int) and floortype (varchar): id 1 = 1, 3, 4 Code:
Remove Element From Array
How do I remove an element from an array? Here is my current code: $sql = mysql_query("SELECT suitenos FROM gssettings WHERE id=1"); $row = mysql_fetch_assoc($sql); $suites = split(",",$row['suitenos']); $number_of_suites = count($suites); for($i=0;$i<$number_of_suites;$i++) { if($suiteno == $suites[$i]) { $selected = "SELECTED"; } else { $selected = ""; } echo<<<endhtml <option value="$suites[$i]" $selected>$suites[$i]</option> endhtml; } Now I have another table in my database called "gsdays" that holds values of suite numbers that are already booked. What I want to do is remove any suite numbers that are already booked from my $suites array. To get the booked suites, I would do the following query. $query = mysql_query("SELECT suite FROM gsdays WHERE date='2007-03-24'"); $row = mysql_fetch_assoc($query); $booked_suites = $row['suite']; so basically what I want to do is remove $booked_suites from $suites. I tried using array_splice but I don't know what I'm doing.
Remove Elements From Array
I have some array: $arr1 = array ("a", "b"); $arr2 = array ("a", "b", "c", "d", "e"); Haw can I remove element "a" and "b" from arr2? I want second array look like this: $arr2 = array ("c", "d", "e");
Remove Array Member Based On Key
Let's say I have an array called $x. That array may, or may not, have $x['howdy']. I know how to check and see if 'howdy' is a key member of $x using array_key_exists(), but how can I remove that particular member? I imagine I could step through the array, but that seems very inefficient.
Remove Values Less Then 3 Characters From An Array
How to remove values from an array which has values less then 3 chrs. And rearrange it. Eg., Array ( [0] => an [1] => a [2] => and [3] => more [4] => or [5] => less [6] => equal [7] => plus [8] => pause [9] => stop [10] => if [11] => for ) i want to remove [0] => an [1] => a [2] => and [4] => or [10] => if [11] => for rearrange the array keys Array ( [0] => more [1] => less [2] => equal ......
Remove Characters From POST Array
I have a form and I want to remove " and ' characters from the $_POST array, how can I do this? and no I do not want to add slashes to them or anything like that, I want to remove them.
Remove Row From Array And Move Next Value Into Place Etc
Let's say I have an array like this: $array[0] = "ball"; $array[1] = "bat"; $array[2] = "glove"; $array[3] = "referee"; $array[4] = "strike"; $array[5] = "home run"; Now, let's say I want to get rid of [3] but move the next values up, automatically, into 3,4. For example, $array[0] = "ball"; $array[1] = "bat"; $array[2] = "glove"; $array[3] = "strike"; $array[4] = "home run"; Is there a way to simply do this? I could do it using for loops, but is there a simpler way, like a built in function, that will do this for me?
Remove Spaces From String Extracted From Array
I have a file, containing stock symbols: symbols.dat QuoteIBM SIRI GOOG AMD INTC MSFT DELL I need to extract all symbols from the file, and turn them into a string, each being separated by a "+". QuoteIBM+SIRI+GOOG+AMD+INTC+MSFT+DELL I do this with the following code: $arr = file('data/symbols.dat'); //extract file contents into array $sym = implode('+', $arr); //make array a string, separate each array element with a "+" The end result is the string, though, there is a space after each symbol, before the "+" QuoteIBM +SIRI +GOOG +AMD +INTC +MSFT +DELL Does anyone know how I can get rid of the spaces? I've tried using str_replace, rtrim, etc, though either I'm using them in the wrong order, or they just doesn't work. The string is used in a URL, so there can be no spaces.
Remove Items From Array, Shift Positions
Hey, lets say I have: x = array("red", "blue", "green", "yellow", "orange", "grey"); Now lets say I have a loop that prints out what is in the array. I want to be able to remove blue green and yellow, but effectively shift down everything else in the array (in this case orange and grey) so that orange is now positioned relative to where blue was and grey is where green was. By this I mean x[1] = "blue" and x[2] now quals "grey". How can I do this?
Iterator First Item?
Let's say I have the code: foreach($data as $row) { do something with each $row } Is there a way to do something specific to the first item iterated? Pseudocode: foreach($data as $row) { if first time through iteration do something with $row else do something which each remaining $row } Is this possible? I think I could use a regular 'for' loop, using the length of the $data array as a guide, and then an 'if..else' structure to see if it is the first time through the 'for' loop, but I was looking for a more elegant solution.
Trying To Split The Item...
I'm trying to make a search thru my mySQL database, so it any keywords are found then I'm adding the details to the next item in an array that I create. I've tested the array and it is storing the information into the array properly because it echoes out all of the information correctly. My problem is that, at the beginning of each item in the array I have information that tells me what part of the database it was pulled from and the id number and also how many times the a keyword was found in that specific database entry. So you have something like this.. Code:
Get Last Item In URL String
I realize how elementary this is, I apologize. Maybe that's why I can't find the right answer. I've tried everything from EXPLODEing the string to SUBSTR_REPLACE. Can anyone tell me how to just get the last item in a URL string? Like turn this: /mydirectory/myimg.jpg into this: myimg.jpg
Search Item In Database
I made a function that does a case insensitive search. This works fine. But i'd like to improve that script so that it also returns items from the database that are partly similar to the search string. this is the script atm:
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?
Updating Item Numbers (or IDs)
After a while of deleting records in a MySQL db, there gets to be the gaps in the id numbering system. i.e. 1, 2, 3, 6, 7, 12, and so on. Is there a way to renumber the id system in a table for 1, 2, 3, 4, 5, 6, etc without manually going in and changing those numbers?
Returning Autogenerated ID On New Item
Lets say you have a form that when saved to the mysql database creates a unique incremental id. The form is just the first part of a series of things the user can do, so once the ID is created, the page would need to know immediately what this ID is. Is there a way to grab this ID instantly once it is created? Obviously if this were a sign-up for and a new user name and password are involved, you can have the user login after the initial set up and this select statement would bring back the ID. But the situation I have doesn't work like that. The way I have been dealing with this is simply to have a select statement after the initial insert that requests the record based on a couple of other fields that are likely unique. But this seems like a rather kludgy way of doing it. Is there some other solution.
What Does `Catalog`.item Like '%A-%' Mean? -MySQL?
I am looking at an old query and I cannot remember or figure out what this part of the query means: `Catalog`.item like '%A-%' It is the like '%A-%' I cannot figure out. Then entire query is:[color=blue] > SELECT * > FROM `Catalog` > WHERE `Catalog`.img_status = Ƈ' AND `Catalog`.item_type ='R' AND > `Catalog`.item like '%A-%' > ORDER BY `Catalog`.item_type[/color] And will not work without the Like part
Pulling In One Item Of Four Categories
Ive got an offers table which contains name, category_id I want to display all offers, however the first page will only display four offers (one of each category). My query is as follows so how do I do this part? Code:
Finding # Of Item From Query
I have a query that goes "SELECT item_name FROM products WHERE products.drink = 'juice'" . If I get back 12 results from this query I can make a list using a simple loop, that is fine . If I click on one of these list items I want to go to a detail page, again I can do this no probs. How do I carry over to the detail page the number that the item appeared in the original list, for example if a result was "orange" and it was the 5th one in the list, how do I carry over the number 5 to the detail page?
Populating Form Item From SQL Enum Set Rev#2
$sql = "SHOW COLUMNS FROM table LIKE 'subject' "; $qry = mysql_query($sql) or die("Query not valid: " . mysql_error()); $res = mysql_fetch_object($qry); // This returns a row with a field 'Type' containing 'enum(...)' $res->Type = str_replace('enum('', '', $res->Type); $res->Type = str_replace('')', '', $res->Type); //now the string is something like this: one','two','three $temp = explode('','',$res->Type); //temp is an array with as much elements as the enum while ($temp) print array_pop($temp); This way is much more easier using the elements since they are elements of an array. Cleaver isn't it?
How To Replace An Item In The Url Search String
Using PHP 4, what is the most elegant way to replace a parameter value in a url query string? I want to replace the "Order" parameter, but it could occur anywhere in the query string. myfile.php?Param1=Hi+there&Order=ColumnA&Param3=Bye+Bye myfile.php?Order=ColumnA myfile.php?Param1=Anotehr+example&Order=ColumnA after applying this function, I'd like the result of the above examples to be myfile.php?Param1=Hi+there&Order=ColumnB&Param3=Bye+Bye myfile.php?Order=ColumnB myfile.php?Param1=Anotehr+example&Order=ColumnB
Add Item To Shopping Cart Problem
i have a cart link in all of my listed products on the site. when i press this link i will generate a url like this http://www.mysite.com/index.htm?loc...art&productid=3 after i press this link the site cart.php will be included and add the wanted product to the cart, and show the cart. my problem now is after the cart is showed with the new product in it, when i press the F5 key in the browser to refresh the site, the same product will added to the cart once more, because the previous generated url is unchanged in the browser. have anyone a idea how to fix this problem?
How To Apply Css To A Table That Is The Only Item In A Php File Please
How to apply css to a table that is the only item in a php file please In the page that has just the one table that is to be included in the other 2 pages, there's some heavy css going on, plus the text in the table gets changed quite a lot on a daily basis. Usually, in my program, I can highlught the text that needs a different css applied to it and click on the css style that applies to it, but because the page only has the one table and nothing else, there's no mention of the link to the styles page?
Language Depending Item Url's
I'm using a little newsflash item on my webpage, which is some text in an iframe. I have one newsflash item in English and one in another language, newsflash-english.html and newsflash-other.html How can I serve newsflash-english.html to english surfers and newsflash-other.html to not english users ? depending on the browser language ?
Redirecting To The ID Of Newest Item Created
I have a form that a user submits which creates a product. I want the user to be redirected to product.php?product_i=(the new product id) The problem i'm having is that i dont know the ID of the new product created because the table is set to auto increment. How would i go about finding out the new ID and redirecting to that new product after it has just been created?
Selected Item To Use For Multiple Variables
I've got a list of 'items' and those 'items' have unique 'categories'. I have 1 table for 'categories' that contains a list of category_ids and their 'category_names'. The other table is the 'item' list. And here's where I'm running into difficulty, I'd like to have the 'item' table contain the category_id from my 'categories' table as a Foreign Key and that category_id's 'category_name' in a 'category' field. I'm getting the Foreign Key, but I can't seem to grab the 'category_name' and assign it to my $category variable in the 'item' table. I've got a page to insert items and a page to update these items. I was working with the update first. And I'm able to grab the list of categories and select the correct one, but I'm not seeing where to assign the category_name to the $category variable. Here's dropdown list: Code:
Explicit Numeric Keys Vs Item Position
Say if I have a mixed array: $array = array("item1", "2"=>"item2", "5", "item4key"=>"item4") Is it possible while looping through the array (foreach ($array as $key=>$val)) to check if an item has an explicit key specified instead of its automatically assigned position key?
|