foreach

PHP: Limit foreach() statement?

How can i limit a foreach() statement? Say i only want it to run the first 2 'eaches' or something? ...

PHP: how is an array in a foreach loop read?

We have all heard of how in a for loop, we should do this: <?php for ($i = 0, $count = count($array); $i < $c; ++$i) { // Do stuff while traversing array } ?> instead of this: <?php for ($i = 0; $i < count($array); ++$i) { // Do stuff while traversing array } ?> for performance reasons (i.e. initializing $count would've...

Changing a stuct inside another struct in a foreach loop

The following code prints (when invoking MyMethod): 0 0 0 1 I would expect it to print: 0 0 1 1 Why is this? Code: private struct MyStruct { public MyInnerStruct innerStruct; } private struct MyInnerStruct { public int counter; public void AddOne() { ++counter; } } public static void MyMethod() ...

How do I write this foreach loop as any other kind of loop?

foreach ($a as $b) { do function } ...

Seemingly simple MVC partial view question

I am trying to display my data (images) in two columns of a table in my partial view. The code below does not seem to work as it displays each image in its own row. What am I missing? <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> <%@ Import Namespace="ULS_Site.Models"%> <%var alternating = false;%> <table> <% f...

iPhone Objective-C foreach design question

I'm trying to implement a design as follows: Touch class : acts as an interface, several classes inherit from it MoveTouch class inherits JumpTouch class inherits InterfaceTouch class inherits Then I want to have a list of Touch objects. I then want to be able to strip out all the MoveTouch objects ONLY (not the other ones), and then ...

How can I split and trim a string into parts all on one line?

I want to split this line: string line = "First Name ; string ; firstName"; into an array of their trimmed versions: "First Name" "string" "firstName" How can I do this all on one line? The following gives me an error "cannot convert type void": List<string> parts = line.Split(';').ToList().ForEach(p => p.Trim()); ...

Hide a column programmatically in MS-Access

I want to hide or show a column based on variable data from a users selection. How do you set a column to hidden in MS-Access 2003? For Example, After user change event... For Each ctl In Me.FormNameHere.Form.Controls If (TypeName(ctl) = "Textbox") Then If InStr(GetTextList(), ctl.Name) > 0 Then ctl.hidden = T...

PHP - Foreach loops and ressources

I'm using a foreach loop to process a large set of items, unfortunately it's using alot of memory. (probably because It's doing a copy of the array). Apparently there is a way to save some memory with the following code: $items = &$array; Isn't it better to use for loops instead? And is there a way to destroy each item as soon as they ...

Why is there a "&" in ($arr as &$value)?

$arr = array(1, 2, 3, 4); foreach ($arr as &$value) { $value = $value * 2; } foreach (array_expression as $value) statement foreach (array_expression as $key => $value) statement Does $key mean index of an array? ...

foreach loops & stdclass objects

I've seen similar questions on here but I can't seem to apply the solutions to my problem. I have a variable called $results which I got from an API. I'll change the proper nouns so as to protect my work's customers: stdClass Object ( [out] => stdClass Object ( [count] => 2 [transactions] => stdClas...

Loop through controls in TabControl

I am looking for a way to loop through controls on a particular tab of a tabcontrol. For example, I have a tabcontrol with the following tabs: Cars, Pets, Admin On each of these tabs are several controls to display/edit/save data, etc. On the "Save" button, I would like to loop through the controls for that particular tab to check wh...

Custom container requirement to work with Qt's foreach

What is the bare minimum amount of code to create a custom container that would work with Qt foreach macro? I have this so far template< class T > class MyList { public: class iterator { public: }; class const_iterator { public: inline iterator& operator++ () { return *this; } }; }; and I'm getting ...

Basic foreach loop question

Thanks for the help here: http://stackoverflow.com/questions/1744128/foreach-loops-stdclass-objects I set up a foreach loop, but the problem is that sometimes the result is: Warning: Invalid argument supplied for foreach() in /home/MYACCOUNT/public_html/the script.php on line 81 I think that's when there is nothing to fill...

foreach loop with textbox names.

how do i make a foreach loop from this, i want to change the size only of the textboxes that ends with txt2 br1txt2.Size = new Size(27, 20); br2txt2.Size = new Size(27, 20); br3txt2.Size = new Size(27, 20); br4txt2.Size = new Size(27, 20); br5txt2.Size = new Size(27, 20); ...

Foreach in SQL?

I'm not quite sure how to do this in SQL. Here it is in pseudocode: Take the list of nodes with content type X. For each node, take the value of field Y. Insert into term_nodes VALUES ((tid that corresponds to Y), 4, (nid of node X)) The (tid that corresponds to Y) is given by SELECT `tid` FROM `term_data` WHERE `name` = Y (I'm tr...

XSLT, sort and group by year-date

Hello Regarding Umbraco XSLT version 1. I have aprox. 150 news items in XML. Lets say like this (all is pseudocode until I get more familiar with this xml/xslt): <news> <data alias=date>2008-10-20</data> </news> <news> <data alias=date>2009-11-25</data> </news><news> <data alias=date>2009-11-20</data> </news> etc. etc.... I wo...

[PHP] Finding last entry in a foreach() process

Simple one guys. I have an XML parsed using simplexml_load_file(). The following code: <?php foreach($xml->actors->actor as $actors) { echo $actors.", "; } ?> Gives the following result: John Smith, Amy Adams, Charlie Doe, How do I modify the code such that it gives: John Smith, Amy Adams, Charlie Doe This need...

MySQL foreach alternative for procedure

My problem is fairly simple. I have table sets that store product sets (more products looking like one on the outside - computer, mouse and keyboard for ex.) it's connected M:N using sets_products table to products table. Each product can have parameters (connected again M:N). I have a procedure, that generates all parameters as string...

Java: Alternative to iterator.hasNext() if using for-each to loop over a collection

I'm trying to replace an iterator-based loop over a Java list with a for-each statement, but the code uses at some point iterator.hasNext() to check if it reached the last element in the list. Is there something similar for the for-each alternative? for (Object current : objectList) { if (last-element) do-something-special ...