Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





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

Related Forum Messages:
Remove An Item From And Array Entirely
How do you remove an item from an array...

View Replies !
Remove Item From Array
I'm having some trouble understanding how to remove items from an array. The array is created like this: Code:

View Replies !
How To Remove An Item From An Array
Been looking around on how to remove an item from an array, i need the item totally removing, without a gab in the array, as i will be using the implode fuction afterwards.

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 !
Remove Item From Session Array
i have a simple script that adds an item id to a session Code:

View Replies !
Write A Conditional Statement To See If The Current Item In An Array Is The Last Item.
This seems like it would be so simple, but I haven't been able to solve it. I want to write a conditional statement to see if the current item in an array is the last item. I tried

if (count($array) == (current($array))

but that didn't work. count($array) will give me the number of items in the array. What do I use for the current position in the array.

View Replies !
Array_unique - How-to Get First Item Value In Repeated Array Item
I would like to know how-to get the first value of repeated items too in an array using something like array_unique. Code:

View Replies !
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.

View Replies !
Remove Slashes From (double And Single Quotes)
I have this variable with slashes using mysql_real_escape_string () I want to remove the slashes away from the variable without removing the ect.

$title = mysql_real_escape_string( $_POST['title'] );

In the variable that is currently being inputed: Miki Koishikawa's ordinary life...
Input in the database (as you may already know): Miki Koishikawa's ordinary life...

As you can see what is left is the 's I can't use stripslashes () because that would remove the from and that would leave me with rn.

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 !
Delete Item From Array
How do I search for an item within an array, then delete it?

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 !
Delete An Item From An Index Array?
How can I delete an Item from an index array in php4?

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 !
Preg_split First Item In Array Is Blank
could someone please explain to my why using the code below generates a blank item in $array[0] please. The 'x' from xbox360 is in $array[1]?

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[&#3991;']?

View Replies !
Remove A Single Element Out Of That File Without Deleting The Whole File?
I'm using different files to store some arrays to make administration of a very small job-logger very easy. I currently read the file, remove the element to be deleted, delete the whole file, and write the file again without that element. Is there a way to remove a single element out of that file without deleting the whole file?

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 !
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:

View Replies !
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 ...

View Replies !
Some Arrays From A Single Array
I would like to fill up some arrays taking the values from another array in this way: these are the arrays:

$name
$surname
$age
$country
$job
$notes

$allvalues

I would like to do this simple thing:

$name[0] = $allvalues[0]
$surname[0] = $allvalues[1]
...
$name[1] = $allvalues[6]
...

View Replies !
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.

View Replies !
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:

View Replies !
Get A Single Value Of Array When Doing Print_rÂ
why do i get a single value of array when doing print_r the page contain more than 10,000 record . i dont understand as you can see everything is fine can you tell me the possible solution or error

$qry = "SELECT * FROM categories ";
$result=mysql_query($qry);
$total = mysql_fetch_array($result);
print_r($total);

View Replies !
Get Single Element From Multidimensional Array?
I'm a newb trying to get a specific value out of a multidimensional array in our shopping cart. Heres the var_export() of the array.

I want to get this element from the array : ["amount"]=> string(3) "35%" in the ["Discount"], but all of my feeble attempts have failed. Code:

View Replies !
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]);

}

View Replies !
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:

View Replies !
Unserialize A Single Array Element In A Constant?
I have a question about unserializing a single array element from a
serialized array. Can this be done, or must I first unserialize the
array, and then access the element? For example, given:

$data = serialize(array(&#394;.50',&#390;.00',&#390;.00'));

Can I unserialize individual elements from $data, such as:

$data_element = unserialize($data[2]);

As it is now, PHP will generate a syntax error, forcing me instead to
unserialize the entire array before accessing it:

$new_data = unserialize($data);
$data_element = $new_data[2];

NOTE the value in this is as it relates to CONSTANTS, where arrays must
be serialized before define()'d as a constant.

View Replies !
How To Create A Multi D. Array From Single Query
I am trying to build a multidimensional array with a single query. Code:

View Replies !
Single Array That Only Contains The Values That Exist In Both Arrays.
I've been going through the manual looking for a function but I can't find it but maybe someone here knows whether it exists and what it might be called. I have 2 arrays, I want to reduce those arrays to a single array that only contains the values that exist in both arrays.

View Replies !
Passing Array To A Function As A Single Parameter
how can you pass an array to a function as a single parameter?

View Replies !
Make All The Elements In A Array Into A Single Variable
I have an array which is generated by the result of an SQL query...

What I am trying to do is take that array and insert it into a different table in a single field, so what  I am trying to do is make all the elements in a array into a single variable I can use to insert into a field with each array element seperated by a comma.  This would be easy if the array had the same amount of lines each time but it dosent, sometimes the array has 1 element sometimes it has 5....any ideas??

View Replies !
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?

View Replies !
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? ....

View Replies !
Remove Row From Array
I have a multidimensional array with 3 columns, and a number of rows. Some of these rows have a field/value returning $row['value'][$i] == on (from a form checkbox field).PHP Code:

$product_arr = array();
foreach ($_POST['sent'] as $i=>$value) {
    $product_arr[$i]['quantity'] = $value;
    $product_arr[$i]['name'] = $_POST['name'][$value];
    $product_arr[$i]['price'] = $_POST['price'][$value];
}

If I have four rows with $_POST['sent'] turned on, I will be left with an array with only four rows, even though the array originally has 10 rows. However, I am left with the *first* four rows, not the distinct four rows that I would like to process. If anyone can offer suggestions to how I can remove the entire row if it has a $_POST['sent'] in it.

View Replies !
Remove Value From Array?
I have array and know value that I need to remove from array. How to remove value from regular array (not associate).

View Replies !
Remove 1st And Last Array
I've got an array and it will always contain an empty first value and an empty last value. How can i get rid of them, because they are useless? like such a simple task, but I can't find anything that helps on here or in the manual.

View Replies !
How To Remove A Value From An Array ?
I'm trying to remove "banana" from $stack array

$stack = array("orange", "banana", "apple", "raspberry");

in this way PHP Code:

$stack = array("orange", "banana", "apple", "raspberry");
array_unshift($stack,"banana");
array_shift($stack);
print_r($stack);

But it's not working , this is the result

Array ( [0] => orange [1] => banana [2] => apple [3] => raspberry )

How to remove a value from array , for example [1] => banana ?

View Replies !
Array Remove
Is there an acutal function in PHP for removing an element of an array?

eg: array1 = ("zero", "one", "two", "three");
array1 = remove_element( array1, 2 );
// array1 now contains ("zero", "one", "three");

I have been trying the unset method but this seems to be corrupting my
array (which is holding a set of objects);

I can knock something together with aray_merge, array_splice and
similar but just didn't want to reinvent the wheel.

View Replies !
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.

View Replies !
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:

View Replies !
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.

View Replies !
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");

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved