Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Last active June 21, 2017 08:49
Show Gist options
  • Save remcotolsma/abf2c806a39775d70f68673dbebd6b4e to your computer and use it in GitHub Desktop.
Save remcotolsma/abf2c806a39775d70f68673dbebd6b4e to your computer and use it in GitHub Desktop.
<?php
$offset = 0;
$length = 0;
$data = array(
'1',
'2',
'3',
'4',
'5',
'6',
);
$offset += $length;
$length = 3;
foreach ( array_slice( $data, $offset, $length ) as $item ) {
echo $item, '<br />';
}
$offset += $length;
$length = 2;
foreach ( array_slice( $data, $offset, $length ) as $item ) {
echo $item, '<br />';
}
$offset += $length;
$length = 1;
foreach ( array_slice( $data, $offset, $length ) as $item ) {
echo $item, '<br />';
}
$offset += $length;
$length = null;
foreach ( array_slice( $data, $offset, $length ) as $item ) {
echo $item, '<br />';
}
<?php
$data = array(
'1',
'2',
'3',
'4',
'5',
'6',
);
$item = reset( $data );
foreach ( range( 1, 2 ) as $i ) {
echo $item, '<br />';
$item = next( $data );
}
foreach ( range( 1, 3 ) as $i ) {
echo $item, '<br />';
$item = next( $data );
}
echo $item, '<br />';
$item = next( $data );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment