Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.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
要列表或表的Php数组_Php - Fatal编程技术网

要列表或表的Php数组

要列表或表的Php数组,php,Php,我有一个php: print_r($lack->call('channels.archive')); 返回: Array ( [ok] => 1 [url] => https://thename.slack.com/ [team] => theTeam [user] => jason [team_id] => T1EDES561 [user_id] => U0DD74SB8 ) 如何将该数组放入html列表或表格中?如果要打印包含所有键和值的简单表

我有一个php:

print_r($lack->call('channels.archive'));
返回:

Array ( [ok] => 1 [url] => https://thename.slack.com/ [team] => theTeam [user] => jason [team_id] => T1EDES561 [user_id] => U0DD74SB8 ) 

如何将该数组放入html列表或表格中?

如果要打印包含所有键和值的简单表格,可以执行以下操作:

<?php
    echo "<table>";

    // header row ... not necessary
    echo "<tr><th>Key></th><th>Value</th></tr>";

    // loop through the array
    foreach($lack->call('channels.archive') as $key => $val) {

        // prints out header as a `<th>` and value as a `<td>
        echo "<tr><th>$key</th><td>$val</td></tr>";
    }
    echo "</table>";
?>

简短的单行代码解决方案:

echo "<ul><li>" . implode('</li><li>', $lack->call('channels.archive')) . "</li></ul>";
echo“
  • ”。内爆(“
  • ”,$lack->call('channels.archive'))。“
”;

我喜欢这个!为什么我没想到呢?