PHP Foreach loop take an additional step forward from within the loop -


Basically I have a foreach loop in PHP and I have to do this:

  foreach ($ $)  

as $ x = y = & gt; $ Z) // Get the next value of some stuff / y, z in the loop /

< "post-text" itemprop = " Text ">

foreach for non-associative array.

Use for

Lt; count ($ y); $ x ++) {echo $ y [$ x]; // Existing elements if (array_key_exists ($ x + 1, $ y)) $ y [$ x + 1] echo; // Next element if (array_key_exists ($ x + 2, $ y)) $ y [$ x + 2] echo; // next to the element}

associative arrays , it is a bit more difficult to do this work:

  $ Keys = array_keys ($ y); Get all keys ($ x = 0; $ x & lt; counts ($ keys); $ x ++) for $ {yo $ y [$ keys [$ x]] ; // Current element if (array_key_exists ($ x + 1, $ keys)) resonates per dollar [$ of [$ x + 1]] ;; // Next element if (array_key_exists ($ x + 2, $ keys)) $ y [$ keys [$ x + 2]]; // The element after the next element  

When reaching one of the next elements, make sure they exist!


Comments