我的PHP数组的问题

时间:2017-04-24 00:41:43

标签: php arrays

我尝试练习导入数据,然后从数组中提取数据。我使用538中的复仇者数据集作为练习(不发布完整列表)但无法显示数组。我已经简化到了一点,我显然只是错过了一些愚蠢和小的东西。

非常感谢任何帮助

code on pastebin

<?php

$avengers = [
["Henry Jonathan", 52,"Full", "YES"],
["Janet van Dyne",52, "Full", "YES"],
["Stark Tony",52, "Full", "YES"],
["Robert Bruce Banner",52, "Full", "YES"],
["Thor Odinson",52, "Full", "YES"],
["Richard Milhouse Jones", 52, "Honorary", "NO"],
["Steven Rogers",51, "Full", "YES"],
["Clinton Francis Barton",50, "Full", "YES"],
["Pietro Maximof",50, "Full", "YES"],
["Wanda Maximoff",50, "Full", "YES"],
["Jacques Duquesne",50, "Full", "YES"],
["Heracles",48, "Full", "NO"],
["TnChalla",47, "Full", "NO"],
["Victor Shade",47, "Full", "YES"],
["Dane Whitman",46, "Full", "NO"],
["Natalia Alianovna Romanova", 42, "Full", "YES"],
];

$avenger = $avengers[array_rand($avengers)];
?>

 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>avergers</title>
<style>
 td, th {
   border: 1px solid black;
   text-align: center;
   font-size: 35px;
 }
 tr {
   wdith 100px;
   font-size: 35px;
 }
 </style>

  </head>
  <body>
 <table>
  <tr>
    <th>Name</th>
    <th>Years since joining</th>
    <th>Full member?</th>
    <th>Dead?</th>
  </tr>
  <tr>
    <td><?php echo $avenger[0]; ?></td>
    <td><?php echo $avenger[1]; ?></td>
    <td><?php echo $avenger[2]; ?></td>
    <td><?php echo $avenger[3]; ?></td>
  </tr>
</table>
 </body>
 </html>

*更新了建议的更改 - 仍无法正常工作

This is my current output

1 个答案:

答案 0 :(得分:-1)

我尝试通过回显数组和数组来调试代码,但之后就开始工作了。我不知道它是如何工作的但是这段代码是有用的。

证明 - &gt; http://prntscr.com/f03xt3

代码:     

$avengers = [
["Henry Jonathan", 52,"Full", "YES"],
["Janet van Dyne",52, "Full", "YES"],
["Stark Tony",52, "Full", "YES"],
["Robert Bruce Banner",52, "Full", "YES"],
["Thor Odinson",52, "Full", "YES"],
["Richard Milhouse Jones", 52, "Honorary", "NO"],
["Steven Rogers",51, "Full", "YES"],
["Clinton Francis Barton",50, "Full", "YES"],
["Pietro Maximof",50, "Full", "YES"],
["Wanda Maximoff",50, "Full", "YES"],
["Jacques Duquesne",50, "Full", "YES"],
["Heracles",48, "Full", "NO"],
["TnChalla",47, "Full", "NO"],
["Victor Shade",47, "Full", "YES"],
["Dane Whitman",46, "Full", "NO"],
["Natalia Alianovna Romanova", 42, "Full", "YES"],
];

$avenger = $avengers[array_rand($avengers)];
?>

 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>avergers</title>
<style>
 td, th {
   border: 1px solid black;
   text-align: center;
   font-size: 35px;
 }
 tr {
   wdith 100px;
   font-size: 35px;
 }
 </style>

  </head>
  <body>
 <table>
  <tr>
    <th>Name</th>
    <th>Years since joining</th>
    <th>Full member?</th>
    <th>Dead?</th>
  </tr>
  <tr>
    <td><?php echo $avenger[0]; ?></td>
    <td><?php echo $avenger[1]; ?></td>
    <td><?php echo $avenger[2]; ?></td>
    <td><?php echo $avenger[3]; ?></td>
  </tr>
</table>
 </body>
 </html>

让我知道它是否适合你......