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.
View Complete Forum Thread with Replies
Sponsored Links:
Related Messages:
Searching Arrays Values
I have an exploded array, what I need to do is search for the key(s) which contain my search criteria. So basically, array_search but I don't want to put in the entire value of a key, just part of it. so if an array was: 0=> test1 is awesome 1=> test2 is better 2=> test3 is best I want to search for "best" and get 2 returned. Searching for "awe" should return 0 etc. Is there a function that just searches an entire array for a searchstring? Or do I need to get a loop happening and search each array key individually.
View Replies !
View Related
Searching Two Arrays Fully And Comparing
I'm trying to find matching pages by searching two arrays against each other. The arrays get the keywords from the current page and others stored in a database. I'm not very good with PHP but what I'm doing at the moment is actually working, except it's only printing one found keyword when there are more. Code:
View Replies !
View Related
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:
View Replies !
View Related
Unset Arrays In Arrays.
Am trying to create a simplified - prototype shopping cart. There are three pages - first two are forms that get sent to the self page. You can read the description in the beginning comments ....
View Replies !
View Related
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)
View Replies !
View Related
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??
View Replies !
View Related
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?
View Replies !
View Related
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 :-)
View Replies !
View Related
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:
View Replies !
View Related
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);}}
View Replies !
View Related
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:
View Replies !
View Related
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...)
View Replies !
View Related
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?
View Replies !
View Related
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?
View Replies !
View Related
Arrays And Php
I have one problem with arrays. I have database tables like these: Students -student_id -name -grade and StudentGroups -group_id -members (student_id's in one column like this way "63,65,68,69") Now if I want average grades with groups how I must handle arrays and database queries?
View Replies !
View Related
Arrays?
I am trying to understand arrays, and my assignment is to take this code and figure out how to use arrays in it. I just need a nudge in the right direction... <?php // create short variable names $tireqty = $_POST['tireqty']; $oilqty = $_POST['oilqty']; $sparkqty = $_POST['sparkqty']; $address = $_POST['address']; $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; ?> <html> <head> <title>Bob's Auto Parts - Order Results</title> </head> <body> <h1>Bob's Auto Parts</h1> ........................
View Replies !
View Related
About Arrays
i was going to use arrays to store data into mysql from a form i would get this: $sports_type = array('Football'=>'Football.gif', 'Basketball'=>'Basketball.gif'); so when the form is submitted the name = sports, right now it stores Football or Basketball into mysql, but on another page i wanted to display the results in a table and under sports i wanted the .gif to be displayed, i was wondering the best way to go about this?
View Replies !
View Related
Using Arrays
I have all my variables declared with my arrays, but how do I get it to replace the text in included files? For example: I used FORUM_ID=>"$fid", to declare the forum's id. I have a tpl file included after the variables. How do I get the arrays to be used in the template file so if the contents of the tpl file were <a href='viewforum.php?id=FORUM_ID'>FORUM_NAME[/url]?
View Replies !
View Related
Req With Arrays
I want to use arrays in my website (flat file for a guestbook), but despite having read through countless online tutorials on the topic, I just can't get my code to work. I know there are guestbook scripts out there - but that doesn't help me learn how to programme arrays Code:
View Replies !
View Related
XML Vs Arrays
i've been doing it for personal projects for a few years now, and have even done some extensive professional projects. I've been trying to expand my php abilities and finally decided to look into xml. I know what xml is, and how to format it. Unfortunately, I dont have quite the grasp on what xml is capable of or what, if any distinction it has from arrays. Basically, so far I have found nothing I can do with xml that I cant do with arrays. It could be because I'ms till learning xml but I have yet to see any advantages. So am I missing something, or is xml simply a way to handle what can sometimes be a very abstract comcept of array nesting?
View Replies !
View Related
Mix Arrays
I have one array, and I want to mix the values in this way: Value A vs Value B Value C vs Value D and so on. However I want to print every possible combinations without repeting.
View Replies !
View Related
Use Two Arrays
I want to be able to use column names "name" => "$nameField" so after parsing I use: array_push($events_array, array("name" => "$nameField", "date" => "$dateField", "venue" => "$venueName", "link" => "$linkField")); I then use: $uniqueEvents = array_unique($events_array); this only returns one result.. events_array has all the data in it but $uniqueEvents only has one result so it leads be to believe there is no use for the two dimensional array and it could all be in just one array.
View Replies !
View Related
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>";
View Replies !
View Related
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.
View Replies !
View Related
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
View Replies !
View Related
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?
View Replies !
View Related
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.
View Replies !
View Related
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?
View Replies !
View Related
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.
View Replies !
View Related
How To Intergrade The Arrays
Im tring to create like a telnet script but i dont know how to intergrade the arrays correctly in my script... when i few my script i get c: array in my telnet window... see i have added commands in the array. PHP Code:
View Replies !
View Related
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);
View Replies !
View Related
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 ) ?>
View Replies !
View Related
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
View Replies !
View Related
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])
View Replies !
View Related
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:
View Replies !
View Related
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?
View Replies !
View Related
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?
View Replies !
View Related
Problem Using Arrays
Consider the following program: <?PHP $x[1]="A:B:C"; $y[1]=explode(":",$x[1]); echo "$y[1][0]";?> I was hoping the result would be "A", and $y[1][1] if displayed would have been "B" etc. Obviously this isn't the way to use multi-dimensional arrays, so what's the correct way?
View Replies !
View Related
Working With Arrays
I have a database with users, with unique ID and what I want to do is create users with random IDs, there's a tool for user creationg where you specify the range of posible ids (comonly 1000:9999) and the number of users you want to create (comonly 20). So, I build an array having this key/velue pairs: 1000=>1000 1001=>1001 1002=>1002 ... and then I get all the ids in the database from 1000 to 9999 and I remove them from the array, so I should end having something like (suposing there's a user with id 1001) 1000=>1000 1001=>1002 1002=>1003 I think for doing this, I would have to get the ids and one by one remove them from the array and then run a renumeric loop renumering all the values and then I randomize in the result and I'll always get free ids.
View Replies !
View Related
|