3v4l.org

run code in 300+ PHP versions simultaneously
<?php function sumCarries(array $array) { $columns = ['carries' => []]; // prepare matrix of 1-digit integers in columns -- ones, tens, hundreds, etc foreach ($array as $integer) { $columns[] = str_split(strrev($integer)); } // sum column values in ascending order and populate carry values // subsequent column sums need to include carried value for ($i = 0, $len = strlen(max($array)); $i < $len; ++$i) { $columns['carries'][$i + 1] = (int)(array_sum(array_column($columns, $i)) / 10); } // sum all populated carry values return array_sum($columns['carries']); } $tests = [ [123, 456], // no carries in any column [555, 555], // 1 ones, 1 tens, 1 hundreds [123, 594], // 1 tens [123, 123, 804], // 1 ones, 1 hundreds [99, 9, 99, 99, 99], // 4 ones, 4 hundreds [9,9,9,9,9,9,9,9,9,9,9,9], // 10 ones ]; var_export(array_map('sumCarries', $tests));
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.4, 8.3.6 - 8.3.28, 8.4.1 - 8.4.14, 8.4.16, 8.5.0 - 8.5.1
array ( 0 => 0, 1 => 3, 2 => 1, 3 => 2, 4 => 8, 5 => 10, )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 array ( 0 => 0, 1 => 3, 2 => 1, 3 => 2, 4 => 8, 5 => 10, )

preferences:
193.44 ms | 409 KiB | 5 Q