3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // Say we have a 74-page file $num_pages = 74; // Fill an array of commands. $sections = array(); for ($i = 1; $i <= $num_pages; $i = $i+2) { $next = $i+1; $sections[] = "pdftk A=the.pdf cat A{$i}-{$next} output the_pages_{$i}-{$next}.pdf"; // Or, y'know, run them directly with shell_exec or something. // shell_exec("pdftk A=the.pdf cat A{$i}-{$next} output the_pages_{$i}-{$next}.pdf"); } print_r($sections); // Then of course run them all.
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 [26] => pdftk A=the.pdf cat A53-54 output the_pages_53-54.pdf [27] => pdftk A=the.pdf cat A55-56 output the_pages_55-56.pdf [28] => pdftk A=the.pdf cat A57-58 output the_pages_57-58.pdf [29] => pdftk A=the.pdf cat A59-60 output the_pages_59-60.pdf [30] => pdftk A=the.pdf cat A61-62 output the_pages_61-62.pdf [31] => pdftk A=the.pdf cat A63-64 output the_pages_63-64.pdf [32] => pdftk A=the.pdf cat A65-66 output the_pages_65-66.pdf [33] => pdftk A=the.pdf cat A67-68 output the_pages_67-68.pdf [34] => pdftk A=the.pdf cat A69-70 output the_pages_69-70.pdf [35] => pdftk A=the.pdf cat A71-72 output the_pages_71-72.pdf [36] => pdftk A=the.pdf cat A73-74 output the_pages_73-74.pdf )