I.e. instead of just looping through one array element at a time, but to loop through selected pairs instead (e.g. 3 elements, and then to do something to those 3).
there are many ways to do it.
one would be
$arr = array(1,2,3,4,5,6,7,8,9);
$new = array_chunk($arr,3);
foreach ($new as $chunk) {
print_r($chunk);// 3 elements to do something with
}
Related Contents:
- Notice: Array to string conversion in
- Select from mysql table WHERE field=’$array’?
- How can I sort arrays and data in PHP?
- Can I bind an array to an IN() condition in a PDO query?
- How to sort an array of associative arrays by value of a given key in PHP?
- Multiple inputs with same name through POST in php
- Two arrays in foreach loop
- Modify array values in foreach loop
- PHP Sort Array By SubArray Value
- Get first key in a (possibly) associative array?
- How to find entry by object property from an array of objects?
- PHP Array to JSON Array using json_encode(); [duplicate]
- How to filter a two dimensional array by value
- How can I properly use a PDO object for a parameterized SELECT query
- How to insert element into arrays at specific position?
- Convert array of single-element arrays to one a dimensional array
- PHP – Merging two arrays into one array (also Remove Duplicates)
- How to use a string as an array index path to retrieve a value?
- PHP Difference between array() and []
- php implode (101) with quotes
- More concise way to check to see if an array contains only numbers (integers)
- Echo a multidimensional array in PHP
- Rotate array elements to the left (move first element to last and re-index)
- Group array data on one column and sum data from another column
- Difference between array_map, array_walk and array_filter
- How is the PHP array implemented on the C level?
- Transpose 2d array, join second level with commas, and join first level with pipes
- Remove all elements from array that do not start with a certain string
- How to sort a multidimensional array by a certain key?
- Generate an associative array from an array of rows using one column as keys and another column as values
- How to GROUP BY and SUM PHP Array? [duplicate]
- Sort an array by a child array’s value in PHP
- Merge row data from multiple arrays
- PHP Random Shuffle Array Maintaining Key => Value
- How to split a long string without breaking words?
- Remove item from array if it exists in a ‘disallowed words’ array
- Group 2d array’s row data by one column and sum another column within each group to produce a reduced 2d array
- scandir() to sort by date modified
- Will copy-on-write prevent data duplication on arrays?
- getting a checkbox array value from POST
- Create an assoc array with equal keys and values from a regular array
- PHP get index of last inserted item in array
- Convert delimited string into array key path and assign value
- Sort array in PHP by value and maintain index association
- Unsetting array values in a foreach loop [duplicate]
- PHP: do arrays have a maximum size?
- How to convert array values to lowercase in PHP?
- After array_filter(), how can I reset the keys to go in numerical order starting at 0
- Sort array by value alphabetically php
- Custom key-sort a flat associative based on another array