foreach

The simplest question: extract values from array

So this is an example: Array ( [0] => Array ( [title] => Title_1 [checkout] => 1 [no_gateway] => 0 ) [1] => Array ( [title] => Title_2 [checkout] => 1 [no_gateway] => 1 ) [2] => Array ( [title] => Title_3 [checkout] => 0 [no_gateway] => 0 ) [3] => Array ( [title] => Title_4 [checkout] => 1 [no_gateway] => 1 ) [4] => Array ( [title] =>...

PHP & MS SQL - Foreach Loop?

Hi All, I have a table in my ms sql database and am using PHP. What I am trying to do is: Foreach User in table, get his age and favorite color. And for each entry i want to edit it before it is displayed. For example Each User that is retrieved and displayed on the webpage will be hyperlinked. His/her age will be hyperlinked and the ...

Checkboxes and Image Uploads not in $_POST var?

I have a form. In the form, there is an image upload plus a series of checkboxes. I am trying to loop through the $_POST vars to process them. When I do foreach($_POST as $key => $value){echo "$key $value"; } I only get 'input' $_POST vars outputted. The checkbox values and the image upload value are not. I am utilizing Code Ignit...

Can I call `delete` on a vector of pointers in C++ via for_each <algorithm>?

Suppose I have a std::vector<Obj *> objs (for performance reasons I have pointers not actual Objs). I populate it with obj.push_back(new Obj(...)); repeatedly. After I am done, I have to delete the pushed-back elements. One way is to do this: for (std::vector<Obj *>::iterator it = objs.begin(); it != objs.end(); ++it) { delete *it...

Adding Object NSMutableArray with ForEach Loop

Hello, here is what i am trying to do: NSMutableArray *objectNames = [[NSMutableArray alloc] init]; for (Object *o in objectList){ if (![objectNames containsObject:o.name]) { [objectNames addObject:o.name]; } } I am trying to go through an array of objects, then take the objects name (a string) and add it to a string a...

PHP - when using foreach to loop through array, how can I tell if I'm on the last pair?

I'm trying to 'pretty-print' out an array, using a syntax like: $outString = "["; foreach($arr as $key=>$value) { // Do stuff with the key + value, putting the result in $outString. $outString .= ", "; } $outString .= "]"; However the obvious downside of this method is that it will show a "," at the end of the array print out,...

Did I do this properly? .each() & .click() jquery

Am I doing something wrong? Or is there a better way to do this? This is the code I have: //Create as many li's as needed for(var t = 1; t <= pageLimit; t++) { if (t <= 9) { $('ul.thumb-list').append('<li><p>PAGE ' + t + '</p><img id="' + t + '" src="../jpeg/thumbnails/0' + t + '.jpg" /></li>'); } else if (...

How to break a for-each loop when value is set to prevent a double evaluation?

UPDATE: Improved the explanation so hopefully the problem is clear now :) Hi all! I've got a XML in which transitions of a FSM are declared (and events and states offcourse). Here's a simplified version of the XML which also causes the problem which is described below: <?xml version="1.0" encoding="UTF-8"?> <FSM name="MediaPlayer"> ...

PHP foreach loop

I have the array example below that I am using to dynamically create an SQL query based on the options ticked in a form. The code below tests whether there is a value, if so, append it to the array: if ($lookchild) { $val[]='lookchild'; } if ($mentalcap) { $val[]='mentalcap'; } if ($mentalheal) { $val[]='mentalheal'; } if ($olderpeople...

Multiple Threads reading from the same file

I have a xml file that needs to be read from many many times. I am trying to use the Parallel.ForEach to speed this processes up since none of that data being read in is relevant as to what order it is being read in. The data is just being used to populate objects. My problem is even though I am opening the file each time in the thread...

For Each File Enumerator is empty in SSIS 2005, even though there are files

Hi, In an SSIS 2005 package, I have a For Each File Enumerator which iterates through all *.csv files in a folder. The Directory property (and hence Folder) is specified in the VS 2005 development environment. When I run it from VS 2005, the .csv files in the folder get processed and everything works fine. I set the configuration for t...

Jquery: Select all H2 tags on page, copy the text of those H2 tags to a list.

Is there a very simple way to select all H2 tags on the page, then take the text in those H2 tags and add the text of each one to a list. example: <H2>I'm number one!</H2> <H2>I'm number two?</H2> <H2>I'm number three.</H2> the script will grab those, and copy their contents into a list when the page is loaded: <UL> <LI>I'm number o...

php foreach: put each of the loop result in one variable

Hi, I think this is probably a very simple but I can get my head around! How can I put each of the loop result in one variable only? for instance, $employeeAges; $employeeAges["Lisa"] = "28"; $employeeAges["Jack"] = "16"; $employeeAges["Ryan"] = "35"; $employeeAges["Rachel"] = "46"; $employeeAges["Grace"] = "34"; foreach( $employeeAge...

for each in GCC and GCC version

hi how can I use for each loop in GCC? and how can i get GCC version? (in code) ...

Execute SQLite Inserts in several foreach loops in C# ?

Hello everybody, this is my code I have: I have read that setting up the CommandText should happen only once and not in a loop... but how do I then get the individually item data from the foreach? Someone smart enough to refactor that code, that would be nice :) using (SQLiteTransaction trans = DataAccess.ConnectionManager.BeginTrans...

Problems removing elements from a list when iterating through the list

I have a loop that iterates through elements in a list. I am required to remove elements from this list within the loop based on certain conditions. When I try to do this in C#, I get an exception. apparently, it is not allowed to remove elements from the list which is being iterated through. The problem was observed with a foreach loop....

Why are assignment operators (=) invalid in a foreach loop?

Why are assignment operators (=) invalid in a foreach loop? I'm using C#, but I would assume that the argument is the same for other languages that support foreach (e.g. PHP). For example, if I do something like this: string[] sArray = new string[5]; foreach (string item in sArray) { item = "Some assignment.\r\n"; } I get an err...

Why can't I modify the loop variable in a foreach?

Why is a foreach loop is a read only loop? What reasons are there for this? ...

how do I check if an entity is the first element of a foreach loop

Say I have a foreach loop. I have to do something with the first object of the loop that I don't have to do with any of the other objects. How do I check if the item that's currently in the loop is the first object. ...

Code before foreach loop does not execute.

Yay I finally thought of a title! I have a foreach loop that iterates the ListViewItems and does something with each item. But the problem is not that it doesn't do the work in the loop, but it simply does not execute any code that appears before the foreach loop. Below is the full method: private void pNGToolStripMenuItem_Click(o...