How can the output format of the CSV file be adjusted to display data from different arrays in separate columns instead of rows in PHP?

To adjust the output format of a CSV file to display data from different arrays in separate columns instead of rows in PHP, you can first transpose the arrays so that the data is organized by columns. Then, you can loop through the transposed arrays and write each column to the CSV file.

// Sample arrays
$array1 = [1, 2, 3];
$array2 = ['A', 'B', 'C'];

// Transpose arrays
$transposedArrays = array_map(null, $array1, $array2);

// Open CSV file for writing
$fp = fopen('output.csv', 'w');

// Write transposed arrays to CSV file
foreach ($transposedArrays as $row) {
    fputcsv($fp, $row);
}

// Close CSV file
fclose($fp);