$box_length) { echo 0; } else { for ($i = 1; $i < $block_num; $i++) { $block_length += $block_arr[$i]; if ($block_length >= $box_length) { echo $i."\n"; break; } } }