foreach

Array, how to display the "changing values" only

Let's say I have an array with dates and seasons, there is one entry for each day. I would like to print the array row only when the season value is changing. the array look like that: 2009-10-28 00:00:00 (good season) 2009-10-29 00:00:00 (good season) 2009-10-30 00:00:00 (good season) 2009-10-31 00:00:00 (good season) 2009-11...

jquery fading sequence

Hi there, I am attempting to fade in a set of divs, one after another. I thought I could use the simple For Each function that jquery offers. My code is as follows: $('#menu_activate').click(function(){ $('div.section').each(function(i){ $(this).fadeToggle(); }); }); The good thing about this is that it does iterate thr...

foreach loop does not loop through all item in list - C#

I have a basic foreach loop that calls a static method which makes a connection to a database and inserts some data. For some reason it will only iterate through the first item in the collection when I run the application without debugging. If I debug the application and set a break point on the foreach loop, it will iterate through al...

In C# 3.0 is there any syntax for a block of code that will run only if a foreach doesn't have any iterations?

meaning something like... foreach(blah b in blahblahs) { writeOnMoon(b.name); } default { writeOnMoon("No Blahs!"); } default or, otherwise, or something like that, if this does not exist... do you think it should? ...

Is there a way to modify foreach loop variable?

The following code gives an error message: #!/usr/bin/perl -w foreach my $var (0, 1, 2){ $var += 2; print "$var\n"; } Modification of a read-only value attempted at test.pl line 4. Is there any way to modify $var? (I'm just asking out of curiosity; I was actually quite surprised to see this error message.) ...

edit list inside foreach loop

I have an object with the following structure: (pseudocode) class Client { - int ID - int? ParentID - string Name - datetime CreateDate - int ACClientID - List <Client> Clients } I want to loop through the whole nested structure using a recursive foreach, to set the ACClientID of ALL to a value. I know that the enumerator in a foreac...

C# Not Disposing controls like I told it to...

I have a Panel control. And inside the panel users can add combobox's, textbox's labels etc and drag them around and stuff, and there's a Delete button on my form where if they click it, it will delete all controls inside that panel. BUT this code: foreach( Control control in panel.Controls ) { control.Dispose(); } ... Does not w...

Check Upload file type from an array in PHP.

Hi, I know this has been asked a few times before. However, it's something I've had a problem with for a long time. How can I check if a file extension and mime type are in an array this is the code I currently have. $upload_project_thum = $_FILES['upload_project_thum']['name']; $upload_project_thum_ext = substr($upload_project_thum...

Whats the replacement of For-Each loop for filtering?

Though for-each loop has many advantages but the problem is ,it doesn't work when you want to Filter(Filtering means removing element from List) a List,Can you please any replacement as even traversing through Index is not a good option.. ...

C#: Linq style "For Each"

Possible Duplicate: Linq equivalent of foreach for IEnumerable Is there any linq style syntax for "For each" operations? For instance, add values based on one collection to another, already existing one: IEnumerable<int> someValues = new List<int>() { 1, 2, 3 }; IList<int> list = new List<int>(); someValues.ForEach(x => list....

PHP - Foreach (Array of an Array)

Here is an example: for($i=1; $i < 10; $i++){ $marray[] = array($name, $email, $password); // Lets just say for now, there is real // data for each online being input } foreach ($marray as $e){ echo "Name: ". $e[0]; echo "Email: ". $e[1]; } I forgot to mention: This script works ...

Unexpected behaviour with PHP array references

I'm using references to alter an array: foreach($uNewAppointments as &$newAppointment) { foreach($appointments as &$appointment) { if($appointment == $newAppointment){ $appointment['index'] = $counter; } } $newAppointment['index'] = $counter; $newAppointments[$counter] = $newAppointment; $counter++; } If I print the arra...

c# How to add an eventhandler to many menus in a foreach loop?

Hi! I'm working with the compact framework and i'm making an app for a windows mobile standard. I have an array which contain phonenumbers, and i want to add a submenu foreach number i find in that array. These submenus must be clickable, but i can't figure out how to do it. This is my code: // "menuItemRight" is my main ...

XSLT : how to know I went inside any of several for-each ?

I have several <xsl:for-each/> which run the one after the other. I would like, at the end, to do something if I did not pass in any of them. For only one for-each, I can manage to make a <xsl:choose/> with an appropriate test based on the selector in the for-each, but for a lot of them, it begins to be very ugly. Has anyone a solution...

Removing XElements in a foreach loop

So, I have a bug to remove foreach (XElement x in items.Elements("x")) { XElement result = webservice.method(x); if (/*condition based on values in result*/) { x.Remove(); } } The problem is that calling x.Remove() alters the foreach such that if there are two Elements("x"), and the first is removed, the loop d...

C# - Does foreach() iterate by reference?

Consider this: List<MyClass> obj_list = get_the_list(); foreach( MyClass obj in obj_list ) { obj.property = 42; } Is 'obj' a reference to the corresponding object within the list so that when I change the property the change will persist in the object instance once constructed somewhere? ...

Reference to the iteration number in Java's foreach

How can you refer to the index of an array in the foreach? My code String[] name = { "hello", "world" }; for ( int k : name[k] ) { --- cut --- } I expecting that the foreach -loop will 1. set k = 0 in first iteration so that name[0] works correctly 2. set k = 1 in the next iteration... I get the error message foreach not a...

How can I know a row index while iterating with foreach?

in the next example how can I know the current row index? foreach (DataRow temprow in temptable.Rows) { //this.text = temprow.INDEX???? } ...

Php foreach loop, with looping error messages

Hello, I have a foreach loop that is suppose to check to see if a checkbox is checked by an item. If the checkbox is checked I need to see if the file upload part of the script has a value and if so then proceed to check the file type and size of the file the user is trying to upload. Currently if there is only an error with the firs...

php function to return sql results that contain arrays, as an array

So im having a problem (obviously). I have the following MySQL table data 7 USER1 1,1,1,10,1 The Guys Team 8,7,13,14,16 8 USER1 1,1,1,10,1 The Girls Team 7,12,15 10 USER1 1,1,1,10,1 Dog Team 8,7,14,15 I wrote a function to retrieve the data, and return it. function ShowSetTeams($coach){ $result = mysql_query("...