endforeach in loops?

It’s mainly so you can make start and end statements clearer when creating HTML in loops: <table> <? while ($record = mysql_fetch_assoc($rs)): ?> <? if (!$record[‘deleted’]): ?> <tr> <? foreach ($display_fields as $field): ?> <td><?= $record[$field] ?></td> <? endforeach; ?> <td> <select name=”action” onChange=”submit”> <? foreach ($actions as $action): ?> <option value=”<?= $action ?>”><?= $action … Read more

Add a delay after executing each iteration with forEach loop

What you want to achieve is totally possible with Array#forEach — although in a different way you might think of it. You can not do a thing like this: var array = [‘some’, ‘array’, ‘containing’, ‘words’]; array.forEach(function (el) { console.log(el); wait(1000); // wait 1000 milliseconds }); console.log(‘Loop finished.’); … and get the output: some array … Read more

break out of if and foreach

if is not a loop structure, so you cannot “break out of it”. You can, however, break out of the foreach by simply calling break. In your example it has the desired effect: $device = “wanted”; foreach($equipxml as $equip) { $current_device = $equip->xpath(“name”); if ( $current_device[0] == $device ) { // found a match in … Read more