Skip to content

Instantly share code, notes, and snippets.

@rainbow23
Created June 16, 2019 15:34
Show Gist options
  • Save rainbow23/c32f1a6e31256ff67f3c0a438edc0bf4 to your computer and use it in GitHub Desktop.
Save rainbow23/c32f1a6e31256ff67f3c0a438edc0bf4 to your computer and use it in GitHub Desktop.
ループで0-4になる対応の改善案
<?php
$sample = array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
$begin = 0;
$end = 5;
/*
* 0
* 1
* 2
* 3
* 4
*/
$begin = 0;
$end = 10;
/*
* 0
* 1
* 2
* 3
* 4
* 5
* 6
* 7
* 8
* 9
*/
$begin = 0;
$end = 20;
$cnt = 0;
foreach ($sample as $each) {
if ($cnt >= $begin && $cnt < $end) {
echo $each.PHP_EOL;
}
$cnt++;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment