foreach

Basic PHP MySQL array grouping question

Quick question, which I think has a very easy solution for someone who has anything above the most rudimentary knowledge of PHP/MySQL as I do. I have a list of cities in a variety of states stored in a database with city, state and some other variables. Right now they get pulled as a list sorted by city name: Anchorage, AK Baltimore, ...

Unsetting array values in a foreach loop.

I have a foreach loop set up to go through my array, check for a certain link, and if it finds it removes that link from the array. My code: foreach($images as $image) { if($image == 'http://i27.tinypic.com/29yk345.gif' || $image == 'http://img3.abload.de/img/10nx2340fhco.gif' || $image == 'http://i42.tinypic.com/9pp2456x.g...

How do I limit the number of elements iterated over in a foreach loop?

I have the following code foreach (var rssItem in rss.Channel.Items) { // ... } But only want 6 items not all items, how can I do it in C#? ...

PHP loop through multi-dimensional array

Hello, I am currently working on a site that is being built on codeigniter, I am currently querying the data at the moment I think there could be possible 3 arrays that could be returned as array each with a varying amount of results, my question I cannot for life of me loop through the array I have at the moment, my model looks like...

PHP Foreach Loop and DOMNodeList

I am trying to determine the end of a foreach loop that is seeded with a collection of DOMNodeList. Currently, I am using a for loop would like to avoid having a 'magic' number there. I do know there are only going to be 8 columns, but I would like the code me generic for other applications. Is it possible to convert this to a Foreach...

PHP Foreach Loop and DOMNodeList Collection

I am trying to see if I can convert a for loop to a foreach loop. Reason: Because I would like to make this code more generic and stay away from magic numbers. Although I know the numbers of column in the dataset, I would prefer to make the code more generic. I have tried using the end() and next() functions to try and detect the last...

Foreach loop through ObservableCollection

In WPF app I use LINQ query to get values from ObservableCollection and update the state of some objects: var shava = from clc in _ShAvaQuCollection where clc.xyID == "x02y02" select clc; switch (shava.First().Status) { case 1: x02y02.Status = MyCustControl.Status.First; break...

Windows Workflow Foundation 4.0 Break Out of ForEach<T> Activity

I'm using Visual Studio 2010 Beta 2 to get a head start on learning to use WF4. I'm working in the designer to create a xaml file. I've added a ForEach activity, and inside that ForEach activity have a flowchart that does some conditional processing. I want to be able to break out of the ForEach if one of the conditions is true, but c...

Hashmap.keySet(), foreach, and remove

I know that it's typically a big no-no to remove from a list using java's "foreach" and that one should use iterator.remove(). But is it safe to remove() if I'm looping over a HashMap's keySet()? Like this: for(String key : map.keySet()) { Node n = map.get(key).optimize(); if(n == null) { map.remove(key); } else { map.put(...

foreach php statment

I need to combine two foreach statement into one for example foreach ($categories_stack as $category) foreach ($page_name as $value) I need to add these into the same foreach statement Is this possible if so how? thanks ...

Web form generator PHP class - empty property on foreach

I am currently building PHP class that generates web form for flexibility and localization issues. I am having difficulty assigning a key and value for dropdown input; for some reason the foreach seems does not get array variable ($country_list). Here is my code that I am having difficulty. require_once('_include/country_list.php'); //...

Changing foreach iteration variable and implementation differences between C# and C++/CLI

Consider the following C# code. string[] stringArray = new string[10]; foreach (string s in stringArray) s = "a new string"; // Compiler error - Can't assign to foreach iteration variable Now consider the following valid C++/CLI code. array<String^>^ stringArray = gcnew array<String^>(10); for each(String^% s in stringArray) ...

Advantages of std::for_each over for loop

Are there any advantages of std::for_eachover for loop? To me, std::for_each only seems to hinder the readability of code. Why do then some coding standards recommend its use? ...

XSLT: Matching Xpath attributes to attributes from for-each scope

I guess my problem is quite common, so there must be an easy solution. Consider the following xml snippet: <categories> <category name="cat1" /> <category name="cat2" /> <category name="cat3" /> <category name="cat4" /> </categories> <data> <catval name="cat2">foo</catval> <catval name="cat4">bar</catval> ...

foreach throws exception, why?

I am getting this exception: Collection was modified; enumeration operation may not execute. when executing this section of code: List<T> results = new List<T>(); foreach (T item in items) if (item.displayText.ToLower().Contains(searchText.ToLower())) results.Add(item); return results; I can't see why I get this exce...

Multiple MYSQL queries vs. Multiple php foreach loops

Database structure: id galleryId type file_name description 1 `artists_2010-01-15_7c1ec` `image` `band602.jpg` `Red Umbrella Promo` 2 `artists_2010-01-15_7c1ec` `image` `nov7.jpg` `CD Release Party` 3 `artists_2010-01-15_7c1ec` `video` `band.flv` `Presskit` I'm going to pull images ou...

Loop not looping fully on actioning on first iteration

I am doing a multiple upload using the Multiple_upload library in codeigniter, and form some my loop that creates thumbnails only fires on the first iteration it would seem here is my code function saveContentImages() { $this->load->model('categoryModel'); if($query = $this->categoryModel->getCategoryByContentId($this->input->po...

php loop with countdown

Say i start my counter at 400. How would i execute a foreach loop that will run backwards until 0? pseudocode $i = 400; foreach(**SOMETHING**)){ //do stuff $i--; } ...

Using jQuery to Grab Content

Hello, I'm trying to pull a couple variables from the following block of html. If you wouldn't mind helping, it would be greatly appreciated! <div id="services"> <div id="service1"> <div class="left"> <img alt="Service Picture" src="/images/service-picture.jpg" /> <h2 class="serviceHeading">A Beautiful Header...

Pass multiple variables by reference to a foreach loop (PHP)

Scenario/Problem Isolation: Lets suppose my program uses MULTIPLE variables. At the program beginning I want to manipulate MANY of the variables AT ONCE through a general function with LITTLE CODE, before then later in the process using only distinctive few variables in specific functions. Question: How do I pass multiple variables by r...