我们如何在if语句中检查数组的索引,以及它是否可用而不是跳过或执行某些操作。我在数组函数中使用但它不工作并抛出未定义偏移量的错误。
<!DOCTYPE html>
<html>
<head>
<title>csv view</title>
</head>
<body>
<table>
<thead>
<?php
$num_of_rows = count($missing_record_data);
$num_of_columns = count($missing_record_data[$index]);
for($i=0; $i<=$num_of_columns-1; $i++):
?>
<th><?= $column_names[$i]; ?></th>
<?php endfor; ?>
</thead>
<tbody>
<?php for($i=0; $i<=$num_of_rows-1; $i++): ?>
<?php
if(in_array($missing_record_data[$i+1],$missing_record_data)):
?>
<tr>
<?php for($j=0; $j<=$num_of_columns-1; $j++): ?>
<td><?= $missing_record_data[$i+1][$j]; ?></td>
<?php endfor; ?>
</tr>
<?php
endif;
endfor;
?>
</tbody>
</table>
<h1><strong>Note:</strong>These rows were not imported because the blank fields are required. Rest has been uploaded successfully.</h1>
</body>
</html>
这是错误:
Severity: Notice
Message: Undefined offset: 1
Filename: views/uploaded_csv_view.php
Line Number: 21