Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';我不知道如何制作这个PHP数组表_Php_Html_Arrays_Multidimensional Array_Html Table - Fatal编程技术网

Can';我不知道如何制作这个PHP数组表

Can';我不知道如何制作这个PHP数组表,php,html,arrays,multidimensional-array,html-table,Php,Html,Arrays,Multidimensional Array,Html Table,我似乎不知道如何打印一张有序的表格 我希望最多有7列,它可以根据数组的大小生成任意多的行。该数组是通过一个可以随时更新的URL创建的。(这是steam上的玩家清单) $id=$streamprofile['streamid']; $key='xxxxxxxxxxxxxxxxx'; 如果($id!=null){ $inv=文件\u获取\u内容('http://steamcommunity.com/profiles/“.$id./inventory/json/730/2”); $inventory=

我似乎不知道如何打印一张有序的表格

我希望最多有7列,它可以根据数组的大小生成任意多的行。该数组是通过一个可以随时更新的URL创建的。(这是steam上的玩家清单)

$id=$streamprofile['streamid'];
$key='xxxxxxxxxxxxxxxxx';
如果($id!=null){
$inv=文件\u获取\u内容('http://steamcommunity.com/profiles/“.$id./inventory/json/730/2”);
$inventory=json_decode($inv,true);
$price=file_get_contents('values/response.json');
$value=json_decode($price,true);
foreach($rgDescription['rgDescription']作为$rgDescription){
对于($i=0;sizeof($rgDescription['market\u name'])>$i;$i++){
如果(isset($rgDescription['market_name'])){
打印“”;
}
}
}
}
如果需要查看阵列,则可以找到该阵列


我可以打印出表格,但它总是重复我不想要的项目。那么我该如何解决这个问题呢?非常感谢您的建议。

您只需计算列数:

$max = 7;
$col = 1;
for(...) {
   if ($col == 1) {
      echo '<tr>'; // start new row if on column #1
   }
   echo '<td><img etc....'; // output a column
   if ($col == $max) {
     echo '</tr>'; // if column $max was just output, end the row
     $col = 0; // reset column count, 0 to account for ++ coming up next
   }
   $col++;
}
$max=7;
$col=1;
对于(…){
如果($col==1){
echo“”;//如果在列#1上,则启动新行
}
echo'
“market\u name”
不是一个数组,而是一个数组的元素。如果您对它进行
计数(与
sizeof
相同),它将返回
1
,因为它只分配了一个值。也就是说,$i=0;sizeof($rgDescription['market\u name'])>$i;$i++
的行
的行相同($i=0;1>$i;$i++)
,始终返回相同的结果

foreach
扮演重复部分,然后您会得到一个包含相同行的巨大表

建议:

foreach ($inventory['rgDescriptions'] as $rgDescription) {                                
    foreach ($rgDescription as $rg) {
        if(isset($rg['market_name'])) {
            print('
                <td>
                    <img src="https://steamcommunity-a.akamaihd.net/economy/image/'
                    .$rgDescription['icon_url'].
                    '" alt="'.$rgDescription['market_name'].
                    ' width="80" height="75"></td>');
        }
    }
}
foreach($rgDescription['rgDescription']作为$rgDescription){
foreach($rgDescription as$rg){
如果(isset($rg[‘市场名称’])){
打印('
');
}
}
}

JSON完全无法读取,因为浏览器将逃避缩进。您能否将代码格式粘贴到问题的相关部分中?首先,将表格打印为:echo“”,print\r($inventory,true),'';看看你的代码是否与你所尝试的匹配很好。很简单,谢谢你,出于某种原因,我只是无法理解。谢谢你指出,这基本上是从我网站的另一个部分复制粘贴的,我从那里取出阵列,没有仔细查看。第二个foreach是不需要的。
foreach ($inventory['rgDescriptions'] as $rgDescription) {                                
    foreach ($rgDescription as $rg) {
        if(isset($rg['market_name'])) {
            print('
                <td>
                    <img src="https://steamcommunity-a.akamaihd.net/economy/image/'
                    .$rgDescription['icon_url'].
                    '" alt="'.$rgDescription['market_name'].
                    ' width="80" height="75"></td>');
        }
    }
}