foreach

XSL for-each and value-of

Given the xml: <element>text</element> ... <element>text</element> And xsl: <xsl:for-each select="element"> ... </xsl:for-each> What do I need to put inside the for-each loop to access the text? There doesn't seem to be a corresponding xsl:value-of because select="", select="/", and select="element" are all wrong. ...

Peek ahead when iterating an array in PHP 5.2

Is it possible to "peek ahead" while iterating an array in PHP 5.2? For example, I often use foreach to manipulate data from an array: foreach($array as $object) { // do something } But I often need to peek at the next element while going through the array. I know I could use a for loop and reference the next item by it's index ($ar...

Using foreach loop.

I break the code of the for loop without using break like I have for loop given below.And when i is 1 or 2 or 3 or any else but if condition is true then loop will be terminated because i will be 5 if the condition is true.And so NO need of break is needed there.Beacause I do not want to use break.I have done like this here.It works. in...

gridview check duplicates not using sql

I have a code: foreach (GridViewRow dr in gvCategories.Rows)<br/> { <br/> if (dr.Cells[0].Text == txtEnterCategory.Text.Trim())<br/> <br/> isError=true; <br/> <br/> } Debugging: dr.Cells[0].Text is always "", even there are records. How to use a loop to check each row to find if a record exists in the gridview no...

C++/STL: std::transform with given stride?

Hello, I have a 1d array containing Nd data, I would like to effectively traverse on it with std::transform or std::for_each. unigned int nelems; unsigned int stride=3;// we are going to have 3D points float *pP;// this will keep xyzxyzxyz... Load(pP); std::transform(pP, pP+nelems, strMover<float>(pP, stride));//How to define the strMov...

Invalid argument supplied for foreach() using adldap

I am using adldap http://adldap.sourceforge.net/ And I am passing the session from page to page, and checking to make sure the username within the session is a member of a certain member group, for this example, it is the STAFF group. <?php ini_set('display_errors',1); error_reporting(E_ALL); require_once('/web/ee_web/inclu...

Cast element in Java For Each statement

Is it possible (or even advisable) to cast the element retrieved from a for each statement in the statement itself? I do know that each element in list will be of type <SubType>. I.E.: List<BaseType> list = DAO.getList(); for(<SubType> element : list){ // Cannot convert from element type <BaseType> to <SubType> ... } rathe...

PHP foreach loop help

I am working with a PHP foreach loop and I need it to output some specific HTML depending on which array value it is spitting out. Everytime that the foreach loop hits a $content['contentTitle'] I need it to insert a new table and then from there carry on. Essentially I want the for the loop to spit out a new table everytime a new conte...

Foreach loop returning null values in PHP?

Hello, I have a pretty simple problem. Basically I have an array called $list that is a list of titles. If I do a print_r($list) I get these results: Array ( [0] => Another New Title [1] => Awesome Movies and stuff [2] => Jascha's Title ) Now, I'm running a foreach loop to retrieve their values and format them in an <ul> like so......

Evaluating for loops in python, containing an array with an embedded for loop

I was looking at the following code in python: for ob in [ob for ob in context.scene.objects if ob.is_visible()]: pass Obviously, it's a for each loop, saying for each object in foo array. However, I'm having a bit of trouble reading the array. If it just had: [for ob in context.scene.objects if ob.is_visible()] that would ma...

PHP array and foreach help

Hello, I need some help with an array and a foreach loop, I have an array that is data returned from a database, basically it is a list of titles and images associated with it, it looks a little like this, Array ( [0] => Array ( [contentImageId] => 28 [contentImageName] => yellow.png ...

Foreach over a collection of IEnumerables

I have 3 (Edit) mutually exclusive IEnumerables that I want to iterate over. I want to do something like this: IEnumerable<Car> redCars = GetRedCars(); IEnumerable<Car> greenCars = GetGreenCars(); IEnumerable<Car> blueCars = GetBlueCars(); foreach(Car c in (redCars + greenCars + blueCars)) { c.DoSomething(); } ... The best way ...

For each <item> in CheckedListBox. <item> returns as Object and not as Control

Hello there. I have a CheckedListBox previously populated. I want to loop with a "for each / next" through all items in the CheckedListBox and do a lot of "stuff" with each iteration element of the checkedlistbox. example code: For Each item In CheckedListBox1.Items If item.Checked = True Then 'do stuff like...

Help with converting foreach loop to while loop in c#

I had learnt by reading your great answers here, that it is not good practice deleting items from within a foreach loop, as it is (and I quote) "Sawing off the branch you're sitting on". My code currently removes the text from the dropdownlist, but the actual item remains (just without text displayed). In other words, it isn't deleting...

Letting a new PHP page know a new POST value is an Array?

I have a page that creates an associative array, then passes it as a hidden value to a new PHP page. I have a foreach loop waiting to iterate through it but it coughs up an "invalid argument" error, as if the page doesn't know the value it's working with is an array (Despite "print" showing simply "Array"). This is essentially what I hav...

Removing last word from FOREACH loop

I'm building a basic function, which builds out Mysql WHERE clauses based on how many are in the array. $array = array('id' => '3', 'name' => 'roger'); $sql = "SELECT * FROM table WHERE "; foreach ($array as $k => $v) { $sql .= $k . ' = ' . $v . ' AND '; } which will output SELECT * FROM table WHERE id = 3 AND name = roger AND ...

How do I code a loop for my echo statement?

I get only one printed result in the foreach echo loop at the bottom of the page. <?php defined('_JEXEC') or die('Restricted access'); $db =& JFactory::getDBO(); $query0 = "SELECT * FROM `jos_ginfo` WHERE . . . LIMIT 30"; //echo $query0; $db->setQuery($query0); $ginfo = $db->loadObjectList(); //echo /...

PHP output of foreach loop into a new array.

I know I'm probably missing something easy, but I have a foreach loop and I'm trying to modify the values of the first array, and output a new array with the modifications as the new values. Basically I'm starting with an array: 0 => A:B 1 => B:C 2 => C:D And I'm using explode() to strip out the :'s and second letters, so I want to ...

nested foreach in PHP problem

I'm having problems to iterate twice on the same array: <? $indice=0 ?> <?php foreach ($comisiones as $comision1):?> <tr> <td><?php echo ++$indice ?></td> <td><?php echo tag('select',array('name'=>'comision_'.$indice),true)?> <?php foreach ($comisiones as $comision2):?> <option value="<?php ec...

Java Iterators - Trying to get a for each loop to work

So I have a Tree<E> class where E is the datatype held and organized by the tree. I'd like to iterate through the Tree like this, or in a way similar to this: 1. Tree<String> tree=new Tree<String>(); 2. ...add some nodes... 3. for (String s : tree) 4. System.out.println(s); It gives me an error on line 3 though. Incompatible ...