How can PHP be used to create a matrix with only ones and zeros?

To create a matrix with only ones and zeros in PHP, you can use nested loops to iterate over rows and columns and assign random values of either 0 or 1 to each element in the matrix.

<?php

$rows = 5;
$cols = 5;

$matrix = array();

for ($i = 0; $i < $rows; $i++) {
    for ($j = 0; $j < $cols; $j++) {
        $matrix[$i][$j] = rand(0, 1);
    }
}

// Print the matrix
for ($i = 0; $i < $rows; $i++) {
    for ($j = 0; $j < $cols; $j++) {
        echo $matrix[$i][$j] . " ";
    }
    echo "<br>";
}

?>