任何人都可以帮助我吗?我发现使用PHP编程创建矩阵动态很困难。我想从mysql数据库中获得矩阵动态值。
例如:
INF 56 78 67
45 INF 78 67
45 56 INF 67
45 56 78 INF
这段代码:
function random()
{
$max = 7;
if (isset($_POST['amount']))
{
$amount = (int)$_POST['amount'];
$rows = ($amount > 2 && $amount < 15) ? $amount : 3;
}
else
{
$rows = rand(3, 7);
}
for ($i = 1; $i <= $rows; $i++)
{
for ($j = 1; $j <= $rows; $j++)
{
$this->table[$i][$j] = $i == $j ? INF : rand(0, 99);
}
}
}
function __toString()
{
$str = '<table class="table table-bordered" id="tableInput"><tbody>';
$str .= '<tr><td></td>';
foreach ($this->table as $rowName => $row)
{
$str .= "<td>$rowName</td>";
}
$str .= '</tr>';
foreach ($this->table as $rowName => $row)
{
$str .= "<tr><td>$rowName</td>";
foreach ($row as $columnName => $value)
{
$str .= "<td>";
$str .=
'<input class="form-control" type="text" value="' . $value . '" name="table[' . $rowName . '][' .
$columnName . ']" requied' . ($columnName == $rowName ? ' disabled' : '') . '>';
$str .= "</td>";
}
$str .= '</tr>';
}
$str .= '</tbody></table>';
return $str;
}
由于