我有这个警告的问题
注意:未定义的变量:第35行的C:\ wamp\www\android_connect\cara1.php中的T_Person
警告:在第35行的C:\ wamp\www\android_connect\cara1.php中为foreach()提供的参数无效
第35行是foreach($ T_Person为$ Person)
我不明白这是错误的这是我的PHP代码:
<!DOCTYPE html>
<html>
<head>
<title>Daftar Buku</title>
<!--Bagian CSS untuk Styling Tabel-->
<style type="text/css">
table, th, td
{
border: 1px solid black;
}
</style>
</head>
<body>
<h3>Daftar Buku Terbaru</h3>
<?php
$Person = new SimpleXMLElement('contoh.xml', null, true);
echo "
<table>
<tr>
<th>First name</th>
<th>middle name</th>
<th>Alias</th>
<th>Gender</th>
<th>City</th>
<th>Person ID</th>
</tr>
";
foreach($T_Person as $Person)
{
echo "
<tr>
<td width='200'>{$Person->First_name}</td>
<td width='200'>{$Person->Middle_Name_Person}</td>
<td width='130'>{$Person->Alias_Person}</td>
<td width='80'>\${$Person->Gender_Person}</td>
<td width='130'>{$Person->CityBirth_Person}</td>
<td width='130'>{$Person['Person ID']}</td>
</tr>
";
}
echo '</table>';
?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
因为$T_Person没有设置或不是数组.我相信你的意思是这样做
$T_Person = new SimpleXMLElement('contoh.xml', null, true);
Run Code Online (Sandbox Code Playgroud)