【发布时间】:2016-03-19 14:55:42
【问题描述】:
您好,我的代码不工作,运行代码时出现此错误:
这是代码的第 110 行:
$results = array_merge($results, $game_list[$row][$col]);
这是剩下的代码:
$results = array();
for ($row = 0; $row < $num_rows; $row++){
if (strstr($game_list[$row][2], $search) or strstr($game_list[$row][3], $search)){
for ($col = 0; $col < count($game_list[$row]); $col ++) {
$results = array_merge($results, $game_list[$row][$col]);
$successful = true;
}
}
}
if ($successful == true){
echo "<table>
<tr>
<th>Game ID</th>
<th>Genre</th>
<th>Game Name</th>
<th>Game Description</th>
<th>Rental Cost Per Day</th>
</tr>";
// Set number of table rows
$num_rows = count($results) - 1;
// Set number of table columns
$num_cols = 5;
// Start loop to generate rows
for($row = 0; $row < $num_rows; $row++) {
// Generate row HTML
echo "<tr>";
//Start loop to generate columns (nested FOR loop!)
for($col = 0 ; $col < $num_cols; $col++) {
// Generate column HTML
echo "<td>". $results[$row][$col] ."</td>";
}
// End of columns loop
// Generate end of row HTML
echo "</tr>";
}
echo "</table>";
该代码用于搜索数组 game_list 并查看用户输入的关键字是否在数组中。如果是,则代码将获取数组 game_list 中的整行并将其添加到数组结果中。然后,该数组将在表格中显示给用户。
如果有人可以给我一个很好的解决方案。
【问题讨论】:
-
好吧,
$game_list[$row][$col]是一个字符串,而不是一个数组。你为什么不干脆做:$result[] = $game_list[$row];?