数组之间的回声数组[]

时间:2017-09-06 14:58:48

标签: php

我有一个网站使用json脚本来显示连接到服务器的播放器,我想在我们用于社区的网站上打印它。

因此服务器使用json脚本打印此信息:

[{"endpoint":"127.0.0.1","id":41,"identifiers":"steam:1100001XXXXX","license:d25c32a7dXXXX"],"name":"Juan Carlos","ping":69}]

我的问题是当我想要回显使用ARRAY的steamID而不是 " 1100001XXXXX"

我的代码:

 foreach($data as $object):?>

       <tr>
            <td><?php echo $object->{'id'}?></td>
            <td><?php echo $object->{'name'}?></td>
            <td><?php echo $object->{'identifiers'}?></td>
            <td><?php echo $object->{'ping'}?></td>

你有什么想法帮助我吗?

1 个答案:

答案 0 :(得分:-1)

好的,现在编辑您提供的有效数据。看这里:

<?php
$json = '[{"endpoint":"127.0.0.1","id":27,"identifiers":["steam:11000011190e09d","license:bc7e7c16b4c762c0c2a67160ec68db4559b4c03b"],"name":"Nicro Scaro","ping":73},{"endpoint":"127.0.0.1","id":25,"identifiers":["steam:110000105b1c9bd","license:ba7eb97475632e190bb366d61f97411e2006132e"],"name":"Paolo Gillet","ping":25},{"endpoint":"127.0.0.1","id":20,"identifiers":["steam:110000101facefb","license:425097d969f377ca9b916412893f5c55b9a1c282"],"name":"Genaro Savastano","ping":33},{"endpoint":"127.0.0.1","id":29,"identifiers":["steam:1100001083dff7d","license:6610bb9fd154d505d29f29ca3319473e4da34ee0"],"name":"Steven Stifler","ping":55},{"endpoint":"127.0.0.1","id":21,"identifiers":["steam:1100001041335a7","license:f28c54417b5487064076061e5078fb784ee66912"],"name":"Samuel Vegas","ping":41},{"endpoint":"127.0.0.1","id":26,"identifiers":["steam:110000105f5b25c","license:f6cf282a0a543d923f4c81cab9c7d157343f81e6"],"name":"Thomas Shelby","ping":36},{"endpoint":"127.0.0.1","id":23,"identifiers":["steam:110000117812da2","license:50dd53775bccb021c5bbb6a142c5961d2f07a43d"],"name":"Thomas Delome","ping":40},{"endpoint":"127.0.0.1","id":31,"identifiers":["steam:110000104b8adb2","license:65f99a4c62163d6e7cb002defc55c03854e2a7ac"],"name":"Bobby Sicouleur","ping":29},{"endpoint":"127.0.0.1","id":11,"identifiers":["steam:110000104481335","license:cd2b817c6655280c34bd1f41f8ae168804ec7ed2"],"name":"Paolo Garcia","ping":16},{"endpoint":"127.0.0.1","id":24,"identifiers":["steam:110000101450e74","license:8139d095f9bf5de832171f07bf60dba5e9665ed3"],"name":"Mohammed Latifi","ping":163},{"endpoint":"127.0.0.1","id":28,"identifiers":["steam:1100001097c401b","license:9fdcc12449270e6528bdf19b2edb7eef1ab1011f"],"name":"Marcel Delahé","ping":27},{"endpoint":"127.0.0.1","id":30,"identifiers":["steam:11000010285a33f","license:019951830b346c77571d90df9b6a96f580c1358d"],"name":"Gérard Leblanc","ping":30}]';

$array = json_decode($json, true);

foreach ($array as $row) {
    echo $row['identifiers'][0]."\n"; 
}

这将回显所有蒸汽标识符。 var_dump($row)看到它拥有的一切。 请参阅此处的代码:https://3v4l.org/7UotT