3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // Say we have a 74-page file $num_pages = 74; // Fill and array. $pages = range(1, $num_pages); $sections = array(); for ($i = 1; $i <= $pages; $i = $i+2) { $next = $i+1; $sections[] = "pdftk A=the.pdf cat A{$i}-{$next} output the_pages_{$i}-{$next}.pdf"; if ($i > 50) { break; } } print_r($sections);
Output for 5.6.30, hhvm-3.15.4 - 3.22.0, 7.0.0 - 7.2.9
Array ( [0] => pdftk A=the.pdf cat A1-2 output the_pages_1-2.pdf [1] => pdftk A=the.pdf cat A3-4 output the_pages_3-4.pdf [2] => pdftk A=the.pdf cat A5-6 output the_pages_5-6.pdf [3] => pdftk A=the.pdf cat A7-8 output the_pages_7-8.pdf [4] => pdftk A=the.pdf cat A9-10 output the_pages_9-10.pdf [5] => pdftk A=the.pdf cat A11-12 output the_pages_11-12.pdf [6] => pdftk A=the.pdf cat A13-14 output the_pages_13-14.pdf [7] => pdftk A=the.pdf cat A15-16 output the_pages_15-16.pdf [8] => pdftk A=the.pdf cat A17-18 output the_pages_17-18.pdf [9] => pdftk A=the.pdf cat A19-20 output the_pages_19-20.pdf [10] => pdftk A=the.pdf cat A21-22 output the_pages_21-22.pdf [11] => pdftk A=the.pdf cat A23-24 output the_pages_23-24.pdf [12] => pdftk A=the.pdf cat A25-26 output the_pages_25-26.pdf [13] => pdftk A=the.pdf cat A27-28 output the_pages_27-28.pdf [14] => pdftk A=the.pdf cat A29-30 output the_pages_29-30.pdf [15] => pdftk A=the.pdf cat A31-32 output the_pages_31-32.pdf [16] => pdftk A=the.pdf cat A33-34 output the_pages_33-34.pdf [17] => pdftk A=the.pdf cat A35-36 output the_pages_35-36.pdf [18] => pdftk A=the.pdf cat A37-38 output the_pages_37-38.pdf [19] => pdftk A=the.pdf cat A39-40 output the_pages_39-40.pdf [20] => pdftk A=the.pdf cat A41-42 output the_pages_41-42.pdf [21] => pdftk A=the.pdf cat A43-44 output the_pages_43-44.pdf [22] => pdftk A=the.pdf cat A45-46 output the_pages_45-46.pdf [23] => pdftk A=the.pdf cat A47-48 output the_pages_47-48.pdf [24] => pdftk A=the.pdf cat A49-50 output the_pages_49-50.pdf [25] => pdftk A=the.pdf cat A51-52 output the_pages_51-52.pdf )