Better exec()

/**
 * Run command and get output and exit code.
 * See https://stackoverflow.com/a/9486083/2277053
 * See https://stackoverflow.com/a/43657546/2277053
 */
function run_command($command) {
    $output = [];
    exec($command, $output, $exitcode);

    // Trim, Remove empty and Reset keys.
    $output = array_values(array_filter(array_map('trim', $output), function($string) {
        return $string !== '';
    }));

    return [$output, $exitcode];
}

var_dump(run_command('ping 127.0.0.1'));