Changing Array Keys After Using Explode
I have used explode to split a string into parts but the the resulting array keys are ints...is there a simple way of changing the keys from numbers to informative values?
View Complete Forum Thread with Replies
Related Forum Messages:
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 !
Searching An Array - Search The Second One With The First Ones Array Keys?
I've been banging my head against this one for awhile. One array has numbers like awz001 for keys and the count of how many times they appear as values. There's about 300 key, value pairs in this array. So Array = ([awz001] => 7, etc...) and the other array is a multi-dimensional Array ( [0] => Array ( [number] => awz001 [0] => awz001 [Section] => Section one [1] => Section one ) Is there away to search the second one with the first ones array keys? Would you do it with two loops? First through the multi then the single?
View Replies !
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 !
Using Max() On Array Keys
i am using an array to store contact data within a session. it looks like this: $_SESSION['contact'][$key][<content>] $key counts the set of records, so i have $_SESSION['contact'][Ɔ'] $_SESSION['contact'][Ƈ'] $_SESSION['contact'][ƈ'] and so forth. [<content>] stands for the fields containing the actual set of data, which are stored within the [$key]-arrays. at one point i need to find out what the highest value of $key is. running max($_SESSION['contact']) simply leaves me with "Array()" as the result. what i am doing wrong, and how do i correct it?
View Replies !
Array With Fes Different Keys
I have an array with fes different keys: $job_name = array (༽/07/2005' => 'name1', ༾/07/2005' => 'name2', ༽/07/2005' => 'name3'); Now I want to print only the ༽/07/2005' job names. Do I need to create a loop or there is another way?
View Replies !
Max And Array Keys
I am trying to find the key value of the largest number in a array. so basically if my array is $thing = array (3, 4, 5,10, 1) I would like to return 3, I figure I need to use Max and Key values, can someone please point me in the right direction?
View Replies !
Automatic Array Keys
My array keys are behaving strangely. In the manual it says calling an array like $array[] = "something" should make the value be put into the next available integer key available. However, my values are being placed with whole sets of blank keys inbetween. Here's what part of the print_r() of the array returns: Code:
View Replies !
Print Out Array Keys Only
Hi, there are lots of examples that show you how to print array values given a key. Do you know how to print keys for a given array. example $myArray = array('a'=>1, 'b'=>2, 'c'=>3, 'd'=>4); How do you print 'a', 'b', 'c','d' only without using any loops?
View Replies !
Printing Out Array Keys
i'm trying to find a simple way of printing out the keys in an array generated by mysql_fetch_array which returns a single row. i.e. while ($row=mysql_fetch_array($result) ) { print out the $row keys and values } is this possible?
View Replies !
Reverse Array Keys
See the following example: [4] => 'value1' [0] => 'value2' [1] => 'value3' [3] => 'value4' [2] => 'value5' should become [0] => 'value1' [4] => 'value2' [3] => 'value3' [1] => 'value4' [2] => 'value5' As you can see, the keys have been reversed such that the lowest key value is now the highest.
View Replies !
How To Get Two Keys From Array Loop?
I have an array that stores ids, each of which is unique. Is there a way to run a for loop and get two keys at a time instead of only one? Example $id = array(1, 2, 3, 4, 5, 6); for loop.... echo key 1 echo key 2 next loop echo key 3 echo key 4 and so on.... Each key must not appear twice so once a key is displayed, it will be removed from any further loops. I need it to display two keys at a time because I will be pairing them up for the next part of the script.
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 !
Recreate The Numeric Array Keys 0
Is there a php function that will recreate the numeric array keys 0 to what ever is in the array or should I just render a new temp array with a while or foreach loop? I'm trying to do some array manipulation and not having the array keys in sequence does not work. Partly I'm trying to create an SQL query with ID='value' OR with a loop but cannot have an OR after the last entry, so I'm ctrying to count() the array and use the condition of 'count() - $key > 1' to insert the OR so that when the last on is reach it does not because it is = to 1. When the array not in sequence the that last key and count value will not work together properly.
View Replies !
Foreach Loop With Array Keys
I am unable to get the following piece of code to work as desired. The fields valuable seems to contain all values however the vaules variable only contains the first assignied with $values = ''' . $arry[$keys[0]] . ''' $keys = array_keys($arry); $fields = '`' . $keys[0] . '`' $values = ''' . $arry[$keys[0]] . ''' foreach($keys as $key) { if($key != $keys[0]) { $fields .= ', `' . $key . '`' $vaules .= ', '' . $arry[$key] . ''' } }
View Replies !
Prepend Array Keys With A String
I have looked on uk.php.net for the function I need but can't find it. Does anyone know what the function is called who's purpose is: to recurse through an array and assign values to keys whilst prepending the key name with a string specified by one of the function parameters?
View Replies !
Getting Deep Array Value Without Knowing Keys?
I've racked my brain for the last few hours trying to figure this one out. I have an array of language strings such as : $lang = array(); $lang['en']['prompt']['hello'] = 'hello' $lang['en']['prompt']['bye'] = 'goodbye' $lang['en']['number']['first'] = Ƈst' This is being used by an ajax routine, so I don't know which string will be requested at runtime. So, I've got $lang and a request ('en_prompt_hello'), and tried a few things such as: $request = explode ($request); $found_string = array_intersect_assoc ($lang, $request); to no avail. Short of having to do a complicated recursion searching at every available depth, is there an easy way to do this?
View Replies !
Sort An Array Using 2nd Dimension Keys
I need to sort an array (configured as shown) based on one of the second dimension keys. [1] ['File_Name'] => test.doc; [1] ['File_Type'] => MS Word; [1]['Size'] => 50; [2]['File_Name'] => test.pdf; [2]['File_Type'] => Adobe PDF [2]['Size'] => 150 [3]['File_Name'] => test.xls; [4]['File_Type'] => MS Excel; [5]['Size'] => 60; For example, I'd like the order of the 1st dimension keys (integer indices) to reflect the order if the array is sorted by the "File_Type" key.
View Replies !
Resetting The Keys Of An Array After Unset ?
I'm trying to delete an element of an array and then reset the keys. $colors = array('red','blue','green','yellow','purple','gold','silver'); $colors_key = 0; //It won't always be 0, it could be 3 or 4, etc. foreach($colors as $key => $value) { unset($colors [$colors_key]); } $new_array = array_values($colors); And then print out the array, I'll get this: Array ([1] => blue [2] => green [3] =>yellow [4] =>purple [5] => gold [6]=>silver); What I would like to get is this: Array ([0] => blue [1] => green [2] =>yellow [3] =>purple [4] => gold [5]=>silver); Anyone know how I can do this?
View Replies !
Array Keys - Check Boxes
I have a bunch of checkboxes and then on the next pg i check which boxes were ticked. Here is my code $i = 0; $array = ""; foreach(array_keys($_POST) as $myKey) { echo "ee"; if (ereg('value', $myKey)) { echo "hi"; $id = ereg_replace("value='checkbox'", "", $myKey); $array[$i] = $id; $i = $i+1; } } If none of the boxes are ticked i get errors. I want to check if boxes were not ticked and if none was ticked then send a user to another page But ive tried every way i can think of and cant get it to work.
View Replies !
Building An Array Using Stored Keys
If I have a list of keys and need to create an array then add a value to the final element, how would I do that? For instance, if I have the string "red" and if I have the stored keys: array(1, 'element', 0, 'property') And I want to build the array: $an_array[1]['element'][0]['property'] = "red"; How could I go about doing that?
View Replies !
Wild Cards For Array Keys?
I have a pretty complex array that stores information for fields. The following array element is a boolean: $_POST['fields'][$i]['listing'] Where $i starts a 1 and can go on for however long the user inputs into the form. So lets say the users input 20 fields. How exactly would I count how many of those array elements are equal to 1, without doing a loop? Is it possible to insert a wild card in place of $i? I already have a lot of nesetd loops and the last thing I want to do is add another one.
View Replies !
Array Keys - Avoid Using Temp
I was wondering if there is a more gracious way to write the below code: //$input is an array .I just need its 0th and 2nd key-not the 1st.I want to avoid using temp $temp=array_keys($input); print $temp[0];print $temp[2];
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 !
Argument To Keys() Should Be An Array In Main.inc On Line 152
I am getting the following errors: Warning: Argument to keys() should be an array in main.inc on line 152 Warning: Non array argument supplied for foreach() in main.inc on line 152 I've developed the site on my linux box at home using PHP 4.0.3pl1. It works great, but when I upload it to my hosting service I get the above messages. I've tried all the different ways to go through an associative array. I've tried doing an implode(array_keys($arr), ',') then split on ','. It keeps coming back to the fact that it doesn't recognize the array I declare right before it is an array. The hosting service runs a BSD Bosx and uses PHP 4.0b2. I'm wondering if this was a problem with the second beta release or if it is something screwy between platforms. Why does it work great on my box but when I upload it it craps out?
View Replies !
Calling Array Keys With Embedded Variables
I'm in the middle of modifying a script and I've come across a problem. I have a form that gets repeated x number of times and each field in the form gets the name $item_number_ . $business_item_index ._(the specific field name). These varaibles get reposted to the same page as $_POST variables, so that the forms save the users settings. What I'm trying to do is parse through those fields that the user did not set, and if they are null, to unset them and decrement the counter($business_item_index) so that one less form gets written to the screen the next time the user submits. Code:
View Replies !
Assign Column Names As Array Keys
Want to create an array that has db column names for the key names and field values as the array values. Is there an easy way to do this? If not possible directly, is there a way in php/mysql to get a list of column names in a table such that I could use those values as the keys?
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 !
Getting Keys/values From POST Array In An Orderly Fashion..
I've got this javascript that results in the following being posted; weight_1 = 30 cost_1 = 20 amount_1 = 32 weight_3 = 65 cost_3 = 23 amount_3 = 12 weight_7 = 43 cost_7 = 9 amount_7 = 12 etc.., with the numbers appended to the keys (here 1, 3, and 7) ascending but not sequential. I need my PHP recieving these POST keys/values to present them like this: #1 Weight: 30 Cost: 20 Amount: 30 #2 Weight: 65 Cost: 23 Amount: 12 #1 Weight: 43 Cost: 9 Amount: 12 Whats' the right way to do this? I've been messing around with array functions but haven't quite figured out which to use..
View Replies !
UNSET'ing Multidim Array Elements And Reseting Keys
I have a script that calls code plugins that return associative arrays: $aData[0]... $aData[1]... $aData[2]... $aData[3]... $aData[4]... $aData[5]... $aData[6]... $aData[7]... I would like to run a search on the array data and UNSET the array rows that do not meet my criteria (this part I know how to do). This means I end up with: $aData[0]... $aData[1]... $aData[3]... $aData[5]... Once this is done, I'd like to reset the first level key names to be consecutive like this (this is where I need help; I'm hoping for a existing builtin function but so far have not been able to find one): $aData[0]... $aData[1]... $aData[2]... $aData[3]... I'll find out soon enough once this is working but does anyone know is UNSET eats up alot of time? on large arrays?
View Replies !
Question About The Behavior Of String Associative Array Keys
I am trying to use an associative array to pass names and scores to a JPgraph but I believe I may misunderstand something about associative arrays. Say I have an array called $kidscores where: $kidscores=(Johnny_Jones => 50, Sally_Smith => 100, Tommy_TheCat =>75) When I pass the $kidscores variable to JPgraph, and try to.... PHP Code:
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 !
|