Element From An Array
I have an array that contains numbers. Each element in the array is guaranteed to be unique.Let's say I have another variable which I know for certain is in the array, but I don't know the position.
View Complete Forum Thread with Replies
Sponsored Links:
Related Messages:
Take The Entire Array And Apply The Htmlentities Function To Each Array Element
what I want to do is take the entire array and apply the htmlentities function to each array element. So here is what I am doing: $result = $dbconn->query("select * from tablename"); while($case = fetch_array_html($result)) Here is the function: function fetch_array_html($result) { $arr = mysql_fetch_array($result); foreach($arr as $key=>$val) { $arr[$key] = htmlentities($val); } return $arr; } Here is the error I get: Warning: Invalid argument supplied for foreach() on line 129 What exactly am I doing wrong here? I can usually fix my own errors, but this one is dominating me.
View Replies !
View Related
Array Element Disappears And The Whole Array Collapses And Renumbers Itself
checkbox arrays do not hold their respective positions as do other field arrays that are established to store the contents of selected records. The problem is that when you "uncheck" one of the elements and then repost, that array element disappears and the whole array collapses and renumbers itself with only the remaining "checked" ones -- simply useless when dealing with records in a table where all the field array elements should be in sync. I consider it a bug -- why does the array have to collapse? Why can't it just hold a null value and keep its position? The only fix is to never hold checkbox values in an array. Store them in individual variables numbered like an array, then do an "eval" to retrieve the contents. Here's the whole thing in action: Code:
View Replies !
View Related
How To Get Array Element?
get_the_category() returns an array that looks like this: ResourceArray ( [0] =stdClass Object ( [cat_ID] =3 [cat_name] => Certifications [category_nicename] =ms-certifications [category_description] =Certification Resource [category_parent] =0 [category_count] =5 [fullpath] =/ms-certifications ) ) I want to get the value in "category_description" and have tried: $category = get_the_category(); $cat_d = $category->category_description; print_r($cat_d); But that doesn't print anything. What is the correct way to get the value I'm after?
View Replies !
View Related
Array Element
I am having trouble getting a weather sticker php script to work properly. I have been working with the guys that wrote it, but so far they haven't come up with a solution. They/we have narrowed it down to the section of the script that compares a text string (which has been converted into UPPER CASE) from a file generated by the weather station, with an array. It is supposed to match an index in the array, that points to which graphic file to generate. This works about 30% of the time. (When the text string is VERY SIMPLE - like CLOUDY or CLEAR or RAIN) But not when the text string is more complex, like HEAVY RAIN, MIST OVERCAST, LIGHT RAIN or PARTLY CLOUDY. Here is the line that defines one of the elements in the array: Quote $vws_icon["PARTLY|MOSTLY+CLOUDY|SUNNY+THUNDERSTORM"] = "./icons/" . "$daynight" . "_tstorm.$image_format"; I did not incluse the whole script, nor the whole array because of its length. My Question (Finally...) is --- in the line above within the square braces, he has enclosed a string in double quotes, but the string is delimited by | characters and + characters. Can someone explain to me in English what this means? I have tried reading through two big reference books on php arrays, and they only made me even less certain. (For example: "the line means - If the string is PARTLY or MOSTLY CLOUDY or SUNNY and THUNDERSTORM, then set $vws_icon to whtever the $daynight._tstorm.$image_format evaluates to.) I know, my example translation makes NO SENSE in English. Maybe it makes no sense in php either? I think what he's trying to ask is "If the string contains 'THUNDERSTORM' and any of these other words, then generate the correct icon file for thunderstorm".
View Replies !
View Related
Using The Last Element In An Array
This is the code I have: PHP Code: $sql = mysql_query("SELECT * FROM dt_directories WHERE category = '$category' ORDER BY name") or die(mysql_error()); $last_sql = mysql_query("SELECT * FROM dt_directories WHERE category = '$category' ORDER BY name DESC LIMIT 1") or die(mysql_error()); while ( $last = mysql_fetch_object($last_sql) ) { $last_element = "$last->name"; } while ( $dirs = mysql_fetch_array($sql) ) { $allowed_dirs = $allowed_dirs."name = '$dirs[name]' OR "; } What this does is output the following into the variable $allowed_dirs: E.G - name = 'Best of the Web' OR name = 'Dmoz' OR name = 'Yahoo!' OR Another part of the code outputs the last element in the array to the variable $last_element, in the example above, $last_element would be "Yahoo!". What I want to do is use $last_element to remove the last "OR" in the example above. Any ideas?
View Replies !
View Related
Sum One Array Element
I have an array that contains two elements partNo and Quantity. I want to sum the quantity element for all values in the array. From what I can tell array_sum() sums all elements and converts non-numeric fields to their number equivalent or something. whatever it does I don't get a good total. I'm sure there is an easy solution but I'm hitting a wall.
View Replies !
View Related
Add Element Onto Array
I have an array that has been already created from a script. Here is the code for that array: $returnArray[]= array("id" => $smilieRow['id'], "url" => $smilie->url, "bbcode" => $smilie->bbcode); I have another array too that is created pretty similarly to that. What I want to do is add another element to the array called "$num". Now I would just loop through it again with a foreach, but is there an easier way?
View Replies !
View Related
Get Value Element From Array:
removing one key=>value element from array: I have an array of this sort: array( [#document]=> <?xml version ="1.0"?> [finemae]=>2344ddd [subscriptionstatus]=>unread [trackingnumber]=>45566 } I wanted to get rid of the first Key=>value element which is #document=> <?....?> element: insert into table (#document,filename,subscriptionstatus,trackingnumber) value ('"<?...?>','..',...);
View Replies !
View Related
Delete Array Element
How can i delete an element from one array. Let us suppose that i've an array of 10 elements $a[0], $a[1], $a[2]...etc And when i delete $a[2] i wanna the elements to be re-ordered like this $a[0] will be the same $a[0] $a[1] will be the same $a[1] but $a[2] will be the $a[3] element i had before deleting $a[2] It would be called in Delphi, HOW TO DELETE AN ELEMENT FROM A COLLECTION? Is this possible? Have i to use another type of data? Hope you've understood the idea.
View Replies !
View Related
Deleting An Element In An Array??
Here is the problem: I've got an array with the following elements $array = ("ice","ice","polka","skate","polka"); thats 2 polka, 2 ice and 1 skate Now i want someway of removing just one of the polka's from it.. so that i'd be left with: $array = ("ice","ice","skate","polka"); what i did was a basic search with for loop and break Code: for($x=0;$x<sizeof($array);$x++) { if($array[$x] == "polka") { echo("match ".$x); break; } } alls well n good till now.. now i've got the index value(2 in this case) of the element which needs to be deleted.. but what should be done now?? is there any function which'll let me delete a particular element in an array? Is there any other way to go around this?
View Replies !
View Related
Editing An Element Within An Array
I have a two-dimensional array that looks like this: array( array(0, 123), array(0, 234), array(0, 345), array(0, 456) ) I want to REMOVE any element that contains 234, and I want to INCREMENT the first value for any element that contains 345, to make it look like this: array( array(0, 123),...
View Replies !
View Related
How To Substract An Element From An Array
I'm looking for a function which substracts an element from an array. For example, $array = array ("green", "red", "blue", "grey" ); array_substract($array, "red" ); now it's like I had : $array = array ("green", "blue", "grey" ); notice that the order should be preserved!
View Replies !
View Related
Missing Array Element
I am trying to store the id's for 3 hotel rooms into an array called $rooms, using a simple mysql select statement. Here is the code: <?php require_once('Connections/Vita_Italiano.php'); ?> <?php mysql_select_db($database_Vita_Italiano, $Vita_Italiano); $query_rsAllRooms = "SELECT * FROM room"; $rsAllRooms = mysql_query($query_rsAllRooms, $Vita_Italiano) or die(mysql_error()); $row_rsAllRooms = mysql_fetch_assoc($rsAllRooms); $totalRows_rsAllRooms = mysql_num_rows($rsAllRooms); // create array of all rooms while ($row_rsAllRooms = mysql_fetch_assoc($rsAllRooms)) { $rooms[]= $row_rsAllRooms['Room_Number']; } ?> When I use <?php print_r($rooms);?> to display the contents of the variable, the array only contains 2 room numbers, instead of 3. These are stored in $rooms[0] and $rooms[1]. Does anyone have any ideas what is going on here?
View Replies !
View Related
Missing Element In Array?!
I have the following query I run to pull some data from the db. The sql (when run on the db) returns 2 elements. However, if I var dump my variable ($aidlook) then the first element in the array does not show up. $getaid = mysql_query("SELECT a_uid FROM `answers` WHERE `qid` = $qid", $db); $aidlook = mysql_fetch_array($getaid,MYSQL_NUM); Doing a var dump returns: array(1) { [0]= string(1) "4" } I should be getting 2 elements (4 and 5). I am totally baffled. code as follows: ********************* if (!is_array($aidlook)) $aidlook = array($aidlook); // Check for the existence of the array in case of null returns if (!in_array($userid,$aidlook)) // Look for our element which in this case is "5" { if ($qstatus === 1) // Do a status check { } answer_box($qid,$answ); // additional function being run } else { echo "Your Text Here"; } }
View Replies !
View Related
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 !
View Related
Sort 2D Array (by Value Of Second Element)
I was looking forward to sorting an array by the value of the second element. e.g.: Sort by number of hits: <?php $webs = array (    array("url" => "example.com", "name" => "example 1", "hits" => "5"),    array("url" => "example.org", "name" => "example 2", "hits" => "20"),    array("url" => "example.net", "name" => "example 3", "hits" => "10") ); ?>
View Replies !
View Related
Foreach Seems To Only Get Last Array Element
I'm probably doing something stupid that I just can't see (it is 3:30am here). Here is the result of print_r($children): Code: Array ( [0] => Array ( [id] => 1380 [fname] => Mary [lname] => Contrary [status] => 1 [type] => 2 [email] => Mary.Contrary@nowhere.xxx ) [1] => Array ( [id] => 1378 [fname] => Jane [lname] => Doe [status] => 0 [type] => 2 [email] => Jane.Doe@nowhere.xxx ) [2] => Array ( [id] => 1379 [fname] => John [lname] => Smith [status] => 1 [type] => 1
View Replies !
View Related
Hide Array Element
I am just wondering how I can hide a directory from showing? I've been playing around with files and it doesn't show the "." and ".." for parent folders but I can't seem to make it hide the "admin" folder (which is in the folder "Folder"). I have tried using unset but without success. Code:
View Replies !
View Related
Using An Array Element And Substr
Hi, just new to the list, but couldn't find anything about this on google so I hope it's never been asked before. I'm trying to write a function that takes a rather large (ASCII) string and splits it into distict sections. The input string is beyond my control since it will be read from a magnetic card (like a creditcard). The string looks like this: ....
View Replies !
View Related
Making Third Element In Array =0
PHP Code: Array ( [2005-08-21] => 20 [2005-08-22] => 20 [2005-08-23] => 20 [2005-08-24] => 20 [2005-08-25] => 20) The above is my array, the day of each date is sun(21), mon(22), tue(23), weds(24), thurs(25). i use the code below which reports back the day of the week of each day. PHP Code: $day = date('w', $dates); output 0 1 2 3 4 what i want to do is somehow to make the third element in the array = 0 if the first two elements that falls on a day between 0 and 4 (sun and thurs) i.e if the days are 0,1,2,3 then 2 should = 0 or if the days are 3,4,5,6,0 then 0 should = 0.
View Replies !
View Related
Delete Element Of Array
I am trying to check if any of the elements in a certain array (which is to be inserted into a mysql table) are already listed in the table. For example I have an array containing multiple URL's, and I want to check whether any of these urls is already in my table. If it is i need to remove that particular element of the array. Can anyone point me in the right direction, i am currently trying array_search and in_array.
View Replies !
View Related
Removing Array Element
I have this array: $array[0]["ID"] = 3; $array[0]["name"] = "jan"; $array[1]["ID"] = 5; $array[1]["name"] = "piet"; $array[2]["ID"] = 6; $array[2]["name"] = "joris"; I want to search the array for "piet". If it finds "piet", then this is what my array should look like: $array[0]["ID"] = 3; $array[0]["name"] = "jan"; $array[1]["ID"] = 6; $array[1]["name"] = "joris"; So it has to remove all of $array[1], then update the keys so there's no "gaps" in the array.
View Replies !
View Related
How To Add Element In Array Dynamically?
I want to add two element in a array. the first one is the key and the second is the value.but I want to add it dynamically. i want to do it like the following code: $arr=""; for($i=0;$i<20;$i++) { $arr[$i]=arr($i=>$i+1); array_push($arr[$i]); } print_r($arr); But of couse it don't work. Could anyone tell me how to do it ?
View Replies !
View Related
Deleting An Array Element By Value
I've been trying to figure out how to delete a part of an array by its value... for example, if I have an array called $numbers with the values 1, 2, 2, and 3 (with arbitrary keys), how would I go about deleting one of the ƈ's? I tried using the function: array_diff( $numbers, array([ƈ']) The problem is, this deletes ALL of the elements with the value ƈ' when I only want to delete one of them. Any ideas?
View Replies !
View Related
Using $ POST With An Array Element
$_POST['class[1]'] doesn't seem to work. This works: <input name="class[1]" type="text" value="<?PHP if(isset($class[1])) echo $class[1];?>"> This doesn't work: <input name="class[1]" type="text" value="<?PHP if(isset($_POST["class[1]"])) echo $_POST["class[1]"];?>">
View Replies !
View Related
Deleting An Element In An Array
I have a value in a database that i seperate by commas and explode() into an array. Im trying to delete one element of the exploded array, implode() the array back into a string and update the database. Here is the code I tried. $array[$id] =""; implode(",",$array); The problem is it still implodes the empy values back into the string. Is there an easy way to delete an element from an array without a for loop that shifts everything forward one?
View Replies !
View Related
Removing Element From Array Using String
I am trying the following based on an example from php.net <?php $array_of_items = array ('A','B','C','D'); array_splice($array_of_items, 'B', 1); foreach ($array_of_items as $array_of_items2) { Print $array_of_items2;}?> I expect the result to be ACD, I am getting BCD, Not sure why.
View Replies !
View Related
Insert An Element In Numbered Array
I need to do the following: Say I have a multidim array: $array = array(); $array[0]['name'] = 'Kevin' $array[0]['age'] = 23; $array[1]['name'] = 'Julia' $array[1]['age'] = 31; $array[2]['name'] = 'Bob' $array[2]['age'] = 26; $array[3]['name'] = 'Drew' $array[3]['age'] = 37; and I have a seperate array: $person = array(); $person['name'] = 'Dana' $person['age'] = 33; now I want to insert the $person array into the $array in such a way that it ends up at index 1 and the subsequent elements get pushed up and renumbered, so $array[1] becomes $array[2] and so on. Does php have a built-in function that does this?
View Replies !
View Related
How To Add An Element To The Middle Of An Associative Array ?
I got an array that consists of elements that are arrays also. Now I wish I could add an element to the middle of it. Let mi give you an example: array ( - array(1,15,apple), - array(2,28,banana), - array(3,41,orange) } I would like to add, let's say, carrot on 2nd position: array ( - array(1,15,apple), - array(2,57,carrot), - array(3,28,banana), - array(4,41,orange) } Array_splice() does not work (or maybe i use it in a wrong way? - it splits an adding element for, in that case, 3 elements). Array_push() adds only to the end of an array. can samobody tell me how to add and element to the middle of an associative array?
View Replies !
View Related
Removing An Element From The POST Array
I have a form that is posting it data to PHP_SELF. This then gets processed and does it's thing. My question is that when I hit the submit button, I get all the data from my form but I also get one item from the Submit button itself. Can I make the submit button not include itself in the POST? Here is an example output of print_r($_POST) Array ( [ACPlatSearch] => -1 [ACDeedSearch] => -1 [ACUserInfo] => -1 [ACPropertySearch] => -1 [ACStatsTotalSales] => -1 [SavePermissions] => Save ) The last element is the submit button, the other ones are checkboxes. I don't want that last one. So is there a simple way to not include it or do I need to loop through the array and remove it manually? I need the rest of the array intact for further processing with array functions.
View Replies !
View Related
|