Arrays
If I have an array looking like this:
<?php
$long=array("len" => 0,"word" => "");?>
How can I add a word onto the end of that list? I need to add the word itself and its length.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Arrays Within Arrays, How To Split
I have been stumped on this one and it is probably easier than I think it is, especially since my brain is fried. This is what my array looks like: array(7) { ["injuredPerson"]=> string(0) "" ["dates"]=> string(0) "" ["describe"]=> string(0) "" ["location"]=> string(0) "" ["type"]=> array(3) { [0]=> string(8) "abrasion" [1]=> string(10) "amputation" [2]=> string(12) "asphyxiation" } ["part"]=> string(0) "" ["times"]=> string(0) "" } This is actually an array of information from a form check. I have the error handling check the form and depending on if there is an error or not, the array gets populated with "" or an actual value(s). I am testing a checkbox area of the form (the name is type, so type can hold an array of values, thats why it currently contains abrasion, amputation, and asphyxiation). I have had no problem going through the array until I get to the area with an array within the array. Let me give you some code so you can see how I am doing this:
Searching Arrays With Arrays
ive looked through alot of the array search functions and i dont think any of them support arrays as the "needle" to search for. so say i had a numeric array, $array1 with say 5 elements, 0-4, each element is a single word, lowercase. say i had another numeric array structured the same way called $array2 with say about 5 elements, 0-4. Is there a function which i could use or does anyone know of an easy way to search every element in $array1 and compair it through each of the elements of $array2? and if a duplicate is found in $array2 have that element be removed or unset? im sure this can be done probably easy with some kind of loop function, but thats my weak point right now in php and im working on it.
Add To Arrays
this is the situation. i am passing variable thru an input form to a function on the same page. within that function, it will determine if the checkboxes are checked, if it is checked, add that value to one array. if it is not checked, add to a different array. i do not know the line to add to an array. i am trying array_push but that is not working. array_fill will not work either (do not have php 4.20 installed)
Different Arrays, How To Tell Them Apart?
Is there a function or way to tell the difference between these two types of arrays: array(1,2,3,4,5,6,7,8,9,0); array(1=>"one", 2=>"two", 3=>"three", 4=>"four"); The is_array() function does not distinguish between the two as they are both arrays and is_array looks to see if its an array, so back to step 1. Anyways, is there a function or workaround to find this out??
Arrays
Is there any way that after filling the array in a loop with values that i can go back and start filling in the same array from scratch with a different set of values.
Arrays
is it possible to have an array (or the equivalent) that allows you to say like $text['hi']; or $text['this'];?
PHP 2D Arrays
Please how do we create 2D array and make it global in PHP.
PHP And Arrays?
How can one tell if a PHP array is a simple array or a hashed array (key/valye). The gettype returns "array", but is there a function that will tell me the type? Also, when you have a mixed array, some flat, some hashed, how can you tell the type of each element?
Using Arrays For Look-ups
Just a quick sanity check... Sometimes it's useful to use an array as a kind of reverse lookup. For example, the indexes being productIDs and the value being it's name. If I do something like this... $x = array(); $x[1] = 'foo' $x[345] = 'foo' $x[12345] = 'foo' .... PHP is intelligent enough only to allocate 3 data chunks for this right? As I type this, it seems far more obvious, but if someone could just confirm :-)
WHILE And Arrays
I appear to have the logic on this one worked out(maybe) but when it goes through the while loop, it only echos the first element of the associated array. Now as a Test I echoed what it should be using as the keys and that works fine. So I don't understand why its failing. With out further ado, heres the problem.. So I have this string in the database, lets say that this string is... PHP Code:
Two Arrays As One
How do I convert the following two arrays into one, and loop through it? Code: $sections = array("Articles", "Bio", "Disc", "Home", "Photos"); $table_ref = array("articles", "biography", "discography", "homepage", "photos"); for ($i = 0; $i < 5; $i++) { if ($section == $sections[$i]) { $result = mysql_query("SELECT * FROM $table_ref$i] WHERE artist_name LIKE '$artist_name' ORDER BY artist_name", $db) or die("<font size="4"><b>Error =(</b></font><br><br>Unable to connect to database. Please try again later."); echo create_page($artist_name, $sections[$i], $result);}}
Arrays
when i submit this form, how can i do similar type of processing for all of them, like the first one i want to add to database, or any other processing maybe not related to database, also .. i can do also for the rest, rather than repeating my codes again and again, i know some sort of array.. but.. how Code:
How To Use Arrays
I want to assign some values from a database into an array. I have two fields, id & name. When I am finding the values from the database, I would like to assign the id to an array and the name into another array. I can do this using the array_push() . How can I then print the array? I tried to just print the variable but it give me 'Array'. Maybe a loop? PHP Code:
Arrays
I have problems in trying to '++' an array value. Every time I find a city I add it in the array, and if I find it many times I increment the value (counter) of the city. Here's the code: $address = "http://www.cji.co.il/bw040609.txt"; $address_local = "bw040609.txt"; $lines = file($address_local); $heading = "Companies covered in this CJI report:"; $heading_line = 0; $towns = array(); for($i=0; $i<count($lines); $i++) { $pos = strpos($lines[$i], "Location: "); if($pos !== false) { list($loc,$town) = preg_split("/: /", $lines[$i]); if(in_array($town, $towns)) { $towns[$town] = 1; echo "Town added: $town<br>"; } else { $towns[$town]++; echo "Town added: $town<br>"; } } } foreach($towns as $key => $value) { print "$key => $value<br>"; } The output is like this:
Arrays
How to create one array that will hold numbers from 3 to 50, their square roots, and number * 10? example: 3, 1.43, 30 4, 2, 40
More About Arrays
Is it possible to read a multi-dimensional array from a file? How would one represent a multi-dimensional array in a flat file? Is this possible? For example, I want to have 3 elements in the array, each of which is an array itself: Element 1 ARRAY (1-4) Element 2 ARRAY (1-120) Element 3 ARRAY (1-1460) I'd like to store this array in a delimitated flat file - all integers. 3|84|753|2|0|349|5|0| ... and so on perhaps I need 2 files? other options? (I know... get a database...)
Arrays
I am reading the php manual online and don't understand the way arrays work. It says arrays take a key, value pair which is fine I guess, but how do I get an old fashion c style array? Are the keys like the indices? say I want an array that contains the numbers 0 through 10, what do I make the keys or does it even matter?
Use Of + With Arrays
In a note on 31-Jul-2002 added to the unshift function the writer stated that array2=arrray1+array2 was equivalent to unshift(arrayw,list(array1)). My php seems to take strong objection to this [Fatal error: Unsupported operand types in /var/www/html/GEM/etFlush/embryo_newFrozen.php on line 417]. Am I doing something wrong? Was the original poster on something? Is this a version problem?
Php Arrays
<? $battle['move_1'] = "water"; $battle['move_2'] = "fire"; $battle['move_3'] = "thunder"; $battle['move_4'] = "rock";?> Now I want to check which array key has the array value fire or anything...is that possiable?
Arrays
I have my array and I have just selected a key outta that array with array_keys(); and I got a key returned now how do I search another array for that key?
Arrays #$%^&$#
I am trying to find a unique record and print it to the screen but I cannot solve the errors as the code is as printed Code:
Arrays
how i can declare array in a form, i need to set an radio input box in the form as an array for later use.
Arrays
I am trying to make an emoticon script but I can't use a parentheses in my text code. For example, "" won't work because the parentheses creates a syntax error. How do I make it so I can use a parentheses in an array? This is my code: $ecodes= array(':('); $images = array('<img src='images/emoticons/sad.gif">');
Arrays
What i wish to do is place numbers into an array and keep the values in there and add new numbers to the array. $array = array("1-a","2-b"); can this be done?
Arrays And Text Box
I want to put the result of an array in a text box but instead of put the value it put Array[]. Here is the code: $i=0; while($row=mysql_fetch_row($result)){ for($j=0;$j<3;$j++){ $arreglo[$i][$j]=$row[$j]; } $i++; } echo" <p align='left' size='><font color='#99CCFF' size='> Fecha: <input type='text' name='fech' value=$arreglo[0][1] size='></font>";
Extensions Arrays
ok I have got variables (here is a example of then):- $type1 = ".jpg"; $type2= ".doc"; $type3 = ""; $type4 = ""; $type5 = ""; up to 10 different types. Here is the problem how would I get the files of those types to b displayed on the screen. As at different times there might b more or less extensions on the screen. Here is some of the coding of which I am planning that I am planning to adopt/change, but I can not work out how 2 get the different types 2 be checked.
Problem In Arrays
I have doubt regarding arrays while ($a <= $b) { $room108 [0] = $a++; echo $room108 [0], ","; } the array $room108 [0] contains 12, 13, 12, 11, 12, 12, 13, 12, 15, 16, 16, 15, 14, 14, 12 what i should do i have the count the number of 12's 13's 14's 15's 16's
For Loop And Arrays
I'm trying to create a function to execute multiple backups at once, using the following code:
Filter Arrays
there's an array where i want to remove one entry. so i use PHP Code:
Arrays In MySQL
Can I store an array into an SQL database and then take it back out and it would still be an array?
Multidimensional Arrays Appropriate For This?
I'm writing a class to obtain package tracking information for UPS. They provide a tool that will do this with xml. I submit a query in a specific format and it returns an xml document, which I then parse with some other functions. The response contains information on the package's location (city, state, zip) and its status (delivered, in transit) and the date & time of each entry. It is possible for one package to have an array of values for location, status, time & date because it is always moving. So, for example, I might get an array of 10 results that provide info about the shipment from start to finish. Currently, I'm storing each value (city, state, zip, delivered/in transit, time, date) in its own array. So, there's an array of 10 elements for city, another for state, and so on. I'm wondering if it's appropriate to have a single multidimensional array instead of one array for each piece of info. The columns would be each individual piece of information (city, state, zip, ....) and the rows can be the number of entries of each piece of information (in my example, 10). My array would then have 10 rows with the required number of columns, each showing the data for that entry. Is this a good solution, or should I stick with one array for each piece of information?
Checkboxes, Arrays And SQL
I am very new with PHP, so I hope someone can help me: With the help of JPJones, I've managed to write a basic search script querying a MySQL database. I would like my users to choose which fields they search from, eg search for "red" in field1, field2 and field7 only. I would use checkboxes for this, using [], eg: <input type="checkbox" id="field[]" value="field1">Field 1 I understand I would have to split the $field array (on the comma delimiter?) and then use it in my SQL statement. Would it be something like this? foreach($fieldarray as $key=>$value) { $sql = "SELECT * FROM table WHERE $fieldarray[i] LIKE '%$searchword%'"; } I have no idea of the correct syntax.
Combining Two Arrays
I want to combine two arrays to form one with the unique elements from the other two. PHP Code:
Passing Arrays
I have an eccomerce site that has a shared secure server this causes problems with my sessions because as soon as you go to the secure server it obviously starts a new session because it is on a different server. Firstly is there a way to stop this. Secondly if not can I easily pass an array to the next page in a form, I don't think this is possible don't all items have to be displayed in the form, each item in the array needs a form field (hidden) in order to pas sit to the next page.
For Loop And Arrays
I'm trying to run through an array which has each value in element 1-3. For example: for($x=1;$x<3;$x++){ echo "$array[$x]" } Is this not valid code, because it doesn't seem to work. Also, is there another way to do this?
Arrays Manipulation
I've gotten to the point where my array isn't throwing up errors (wahoo), but I am not getting the result I want from my check to see if userid and password is authentic. Code: $userpass = array(0=>array('page'=>'Newsletter','usid'=>'Editor','pass'=>'NewNews'), 1=>array('page'=>'Membership','usid'=>'Members','pass'=>'ClubFolk'), 2=>array('page'=>'Calendar','usid'=>'Calendar','pass'=>'GoodDates'), 3=>array('page'=>'Master','usid'=>'Admin','pass'=>'Master')); Here's the validation code: Code: foreach($userpass as $checker) { if(($checker['usid'] == $_POST['user']) && ($checker['pass'] == $_POST['pass'])) { $_SESSION[user] = $_POST['user']; echo "<meta http-equiv='refresh'content=Ɔ url=".$_SESSION[thisfile]."'>"; }} It is coming saying login failed, so my comparison isn't happening or isn't happening correctly.
Randomizing Arrays
I have a problem with randomizing a array, from an mysql database. I want it to be different every time I make an output. This is what i want to be randomized $query="select * from $table where(name like'$name%')"; $result=mysql_query($query); $num=mysql_numrows($result);
Joining Two Arrays Together
I would like to join two arrays togther something like the following. I don't know a simple way to create $stack3. <?php $stack1 = array("orange", "banana"); $stack2 = array("apple", "pear"); // do what for the next line? $stack3 = ($stack1, $stack2); print_r($stack3); // The results I would like // Array ( [0] => orange [1] => banana [2] => apple [3] => pear ) ?>
Arrays And Forms
I have two elements in a form , a text area (justification[]) and a hidden field (prodID[]) I have the following code as a test: foreach($_POST['justification'] as $reason) { echo $reason."<br>"; } foreach($_POST['prodID'] as $pID) { echo $pID."<br>"; } output item reason item reason 2 item reason 3 item reason 4 id1 id2 id3 id4 How can i edit the code as such so that the following out put is displayed: item reason - id item reason 2 - id2 item reason 3 - id3 item reason 4 - id4
Sweeping Arrays
Hi. I have this array: $a[0]['name'] = 'john' $a[1]['name'] = 'kate' $a[2]['name'] = 'mary' i need a way to: 1) check which of the sub-arrays has the name=='kate' 2) get the array index to access other data ($a[x])
Using Arrays In A Form
I have a HTML page which is going to have a form and some of the fields in the form will work like a table to allow the user to enter up to 15 lines on information on 4 columns, this application is to allow someone to enter a recipe into a database, so we will have 15 lines to allow people to enter: Quantity, Mesasure, Ingredient, and a flag to indicate if is optional or not. So I tought that would be better to create a bi-dimensional array and pass it to the php code that is called when submit is hit. So here is what I have done: IN THE HTML FILE:
Problem With Arrays
What I'm trying to do is check if the dates in the array $holi[] matches $evalday (not in an array) but with limited success the data in the array is: $holi[1] = 2006-06-20; $holi[2] = 2006-06-28; $holi[3] = 2006-07-19; $holi[4] = 2008-06-24; $holi[5] = 2006-06-30; $evalday = date("Y-m-d", strtotime("+ 1 days"); if($evalday == $holi) { echo("For the purpose of this excercise, $evalday is a holiday"); }
Multidimensional Arrays
I'm having trouble working with Multidimensional Arrays. Does anyone have any tutorials or links they might share on the topic. The challenges I'm having are sorting by a value in the 2nd array and searching for a value in the second array. Array ( [0] => Array ( [id] => 6 [answer] => A [remote_address] => 24.15.143.7 [date_time] => 2006-06-20 07:35:24 [survey_id] => 1 ) [1] => Array ( [id] => 4 [answer] => B [remote_address] => 24.15.143.7 [date_time] => 2006-06-20 07:35:24 [survey_id] => 1 ) ) I'm just not getting how the php example works with usort() or array_filter().
Arrays Always Use References?
I have the following code: $Foo = new CFoo(); $Foo->Bar = 5; $_SESSION['foo'] = $Foo; $_SESSION['bar'] = $Foo->Bar; $Foo->Bar = 10; echo $Foo->Bar; echo $_SESSION['foo']->Bar; echo $_SESSION['bar']; outputs 10 10 10 How can I force an array to contain an instance rather than a reference, so for instance $_SESSION['bar'] is still equal to 5?
Comparing Two Arrays
What i need to do is compare two arrays and return an array that only has those that are not in the main table.It's similar to what you could do with SQL. Array 1 - List of Everything Array 2 - List of Some of Array 1 What i want to obtain is Those of Array 1 that are not in Array 2. I would prefer not to do the following: function getUnique($array1, $array2) { foreach ($array1, $key => $value) { $array2_key = array_search($array2,$value) if ($array2_key === false) $result_array[] = $value; } return $result_array; } Is there any simplier way of doing this...any predefined function in php that could do this?
Adding To Arrays
I have an array that contains numbers in string elements , i want to convert this to integers, i have made a for loop that uses the number of elements in the array and then adds 0, thereby converting it to an integer. //$chars is the array of strings for ($i=0; $i<$numpoints; $i++) { $array = array($chars[$i] + 0); } I dont know though how to add all these elements to the 1 array, it replaces each element in the array with the new item,
|