1
0
Fork 0
php-coding/4.work2.php

26 lines
550 B
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*
* 输出杨辉三角居中效果直接用html
*/
echo '<p style="text-align: center">';
$n = 10;
$data = array();
for ($k = 0; $k < $n; $k++) {
$data[$k] = array();
}
for ($i = 0; $i < $n; $i++) {
for ($j = 0; $j <= $i; $j++) {
if ($i == $j || $j == 0) {
$data[$i][$j] = 1;
continue;
}
$data[$i][$j] = $data[$i - 1][$j] + $data[$i - 1][$j - 1];
}
}
foreach ($data as $sub_data) {
foreach ($sub_data as $item) {
echo $item.' ';
}
echo '<br>';
}
echo '</p>';