PHP 2D Array Line Breaks

In PHP, each sub-array of a two-dimensional array represents a row of data. You can use a loop to iterate through the two-dimensional array, and add a newline character after outputting the data in each sub-array to achieve automatic line breaks.

For example, suppose there is a two-dimensional array $data as follows:

$data = array(
    array('A', 'B', 'C'),
    array('D', 'E', 'F'),
    array('G', 'H', 'I')
);

You can use a foreach loop to iterate over $data and add a line break after each sub-array to achieve automatic line breaks, as shown below:

foreach ($data as $row) {
    foreach ($row as $value) {
        echo $value . ' ';
    }
    echo "\n"; // 添加换行符
}

The above code will produce the following output:

A B C 
D E F 
G H I 

This can achieve the effect of automatically wrapping when outputting a two-dimensional array.

bannerAds