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 Complete Forum Thread with Replies
Related Forum Messages:
Explode Array Created An Automatic Key For Each Row In The Array.
I have a string, like this: Userid1 Pass1 Userid2 Pass2 Userid3 Pass3 Userid4 Pass4 Each column is tab separated. I want to explode it into an array so that the userid will be the key, and the password the value. I tried to do it like this: $array = explode(" ", $string); // Where $string is the string above. However, this returned both the userid and the password as the value, and created an automatic key for each row in the array.
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 !
Explode Array
I have an array name, text=value, text=value, name, text=value, name,.... and I want to do something like: for($n = 0; $n < count($a), $n++){ //where $a is the array $b = explode ("=",$a[n]); } So that I get a new array $b looking like name,text,value, text,value.
View Replies !
Explode Into An Array?
I'm trying to do: explode some data into another array. I will have the code in a loop so that the data in all elements of $RowData gets split up. I would like $ZoneCodes[0] to contain 4 elements, but I would like them to be in the next dimension. i.e. [0][0], [0][1],[0][2],[0][3] Code:
View Replies !
Explode My Array
i have a loop which stores the values in the array $store...i am using the following script after storing the values in $store now if $store[0 or whatever]="john doe" i want the $link as "john_doe" i tried ereg_replace but that also dont seem to work..so please guide in either cases Code:
View Replies !
Using Explode, On An Array?
Our website has a spanish and english version, the data for both languages are pulled using an arrays of arrays. I have one file that contains all of the arrays, here is an example of one $products = array{ "dirtbike"=>array("dirtbike_eng","dirtbike_sp"), } A session variable is set (0 for English, 1 for Spanish) and the appropiate translation is pulled out of the array based on that. It works great, easy to update and change things on our site...but now we want to take the task of translating and updating the page out of the hands of our web designer (me) and let operations do it. They want a simple text file that they can edit and just upload to the web server for the changes to take effect...here is an example of what I have given them (translation.txt) ID ------ English ----- Spanish dirtbike | dirtbike_eng | dirtbike_sp I can read the translation.txt file fine using $data=file(translation.txt); Now it puts each line into an array. What I want to do, is use explode on each line (using a ' | ' delimiter) and output each line into it's own array of arrays. Code:
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 !
How To Explode Array From File?
contents of myfile.txt = 5035|9638742|11938 // (one line of text) $myfile = "/home/path/public_html/myfile.txt"; $totals = file($myfile); $var = explode("|", $totals[0]); $i = number_format($var[0]); $k = number_format($var[1]); For some reason this is acting funny. I am getting a null value for $k for some reason... Is there a better way to do this?
View Replies !
Array Explode Problem
I have the following: Code: $fontfind .= ཋ,' $fontfind .= ཕ,' $fontfind .= ཟ,' $found = explode(",", $fontfind); When I do: Code: print_r(explode(",",$fontfind)); It prints Array ( [0] => 15 [1] => 25 [2] => 35) but print $found[0]; It prints 1 What's going on?
View Replies !
Explode Into Array Question
I have a 4 character string which can be any 4 characters in any position within the string itself and I want to explode it into an array. Normally I would explode it using a delimeter such as a comma or a space but how do I do it when there is no delimeter??
View Replies !
Explode Array Counting?
I am trying to count the number of pieces of an explode so that I can run a foreach command. My code goes out and grabs work order codes from the database. Then runs and explode command to separate those codes. But I have to count how many codes there are to be able to run a foreach. Any ideas? Code:
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 !
How To Get The Number Of Values In An Array After I Use Explode
I have the following variable which has three areacodes in it: $areacode = "305,954,786" $array = explode(",", $areacode); after i explode $areacode, How to get the info. how many areacodes are there in($areacode). in the above example it is 3 area codes (305, 954, 786) $array[0] equals 305 $array[1] equals 954 $array[2] equals 786
View Replies !
Smarty - 'explode' String Into An Array Or 2 Variables
I've a smarty var, like this: {$var} that is equal to: ttttttttttttt|zzzzzzzzzzzz It can be any size, the important is that they are separated by the '|' How do I 'explode' that into an array or 2 variables in the smarty template ? So I can just use: {$var[0]} = ttttttttttttt; {$var[0]} = zzzzzzzzzzzz;
View Replies !
Explode Text Area Into Array For MySQL Table
On my site, I have a textarea where users enter their sites' information in the following format (tab-delimited): Site Name <tab> Site Description <tab> URL <newline> Site Name <tab> Site Description <tab> URL <newline> (and so on...) I know I have to use the "Explode function and a loop to get the data into an array and enter it into a MySQL table. Would anyone have a snippet of code off-hand that could show me how to do this?
View Replies !
Create A Comma Delimited String That I Can Convert To An Array Using Explode();.
I am attempting to create a comma delimited string that I can convert to an array using explode();. I have the following code: Code: $cPath_new_a = tep_get_path($categories['categories_id']); $cPath_new_b = str_replace("cPath=", "", "$cPath_new_a"); $cPath_new_c = str_replace("_", "", "$cPath_new_b"); $cPath_new_d = substr("$cPath_new_c", -2, 2); $cPath_new_e = $cPath_new_d . ","; echo $cPath_new_e; This outputs 23,53, I need it to output 23,53 Using the substr($cPath_new_e, 0, -1); and/or rtrim() method to remove the last character for some reason removes all of the commas. Am I approaching this the right way?
View Replies !
Add Sql Result To An Array
I am trying to add the results of a query (specifically a particular field's value) to a new array. The result is either an empty array or the last row in the query result instead of all the rows. Code:
View Replies !
Array Result
PHP Code: function match_username()         {             $connection = new db_connect;             $connection->connect();             $this->table  = "bs_user_member";             $this->query  = mysql_query("SELECT username FROM $this->table");                 while ($this->result = mysql_fetch_object($this->query))                 {                     global $uname;                                         $uname = array($this->result -> username);                 }                            } Should show all right?
View Replies !
Getting First Result From Array?
Trying to get the top 10 male authors from my database that works fine .. but id also like to just get the top male author too So since ive fecthed the top 10 , shouldnt i be able to get the top 1 from that? Code:
View Replies !
Mysql Result Into Array?
I have a shopping cart script sending info to a processor. I need to send the qty's and item name's in some sort of string via a single variable to the process form. i.e. (3) Hipster Turnips, (6) Butter Milk Baby Brains, (2) Super Freaks Code:
View Replies !
How To Add Function Result To Array?
The way I'd like to set up a particular set of functions is to have them either return TRUE or, for example: $errors[type] = "Sorry, the file type is not allowed. Allowed types are ".print_array_inline($acceptedTypes).". "; Then later, I have a foreach loop that echos each array element. However, when I echo each array element is doesn't output the whatever the print_array_inline function does. Any suggestions?
View Replies !
Mysql Result Set As An Array
the question is, is there a way of assigning each value returned from the sql query and assinging them to a single array. for example i have a a query like so; $table = "sales_table";         $query = "select treatments from $table where date between  ད/08/2006' and ཕ/08/2006'"; $result = mysql_query($query); because the values stored in the treatments field are imploded as a single string when the user submits the form the value looks like; 1, 22, 33. Code:
View Replies !
Result Of Array Diff()
I'm successfully able to compare two different arrays with array_diff(). The result of this comparison is, of course, assigned to a new array. Unfortunatly (for my purposes) the array indeces of the resulting matching items are retained, yet empty: [a][b][empty][d][empty][empty][g] - and so on. I'm wondering if there's a built-in function that would sequentially assign all non-empty index items of my array_diff() result to a second array, like: [a][b][d][g] I know I can do this with a loop, but am wondering if there's already a function to handle this.
View Replies !
|