Bring the news cycle `How can I skip the first entry and not output?
|
1 answer
Option 1. Use for instead of foreach and start walking through the collection with the first element.
for (int $i = 1; $i < length; $i++) { //TODO } Option 2. Create a boolean variable and check if it has changed.
$flag = true; foreach ($collection as $value) { if ($flag) { $flag = false; } else { //TODO } } Option 3. Remove the first element from the array before passing through it.
unset($array[0]); Option 4. In general, do not fill out the collection with this element at the stage of forming a query to the database.
- 3in the
forloop, it's easier to start with 1 without anyif, don't you think? - Alexey Shimansky - @ Alexey Shimansky, of course, easier :) Corrected - koks_rs
|
limit-offset), or in the controller (in logic (array_pop)), and not at the final stage in the view. - teran