关联数组和格式的问题

时间:2017-02-20 19:45:42

标签: php html arrays

我一直在尝试使用grafana嵌入式图表创建仪表板。我对格式化它们有一些问题,我认为这是我编码不正确的问题,但在调查并创建了一个关于它的不同帖子之后,我已经确认这应该并且确实正确地输出了我的所有小程序。我的问题是它没有显示它们,而是只显示数组中的第一个。

我的代码:     

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$dl = array
(
    'dashlet1' => array(
        'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=6',
        'height' => '200',
        'width' => '450'
    ),
    'dashlet2' => array(
        'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=7',
        'height' => '200',
        'width' => '450'
    ),
    'dashlet3' => array(
        'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=11',
        'height' => '200',
        'width' => '450'
    ),
    'dashlet4' => array(
        'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=4',
        'height' => '200',
        'width' => '350'
    ),
    'dashlet5' => array(
        'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=8',
        'height' => '200',
        'width' => '450'
    ),
    'dashlet6' => array(
        'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=10',
        'height' => '200',
        'width' => '450'
    ),
    'dashlet7' => array(
        'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=3',
        'height' => '200',
        'width' => '450'
    ),
    'dashlet8' => array(
        'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=5',
        'height' => '200',
        'width' => '350'
    )
);
foreach ($dl as $element) {
    $url = $element["url"];
    $height = $element["height"];
    $width = $element["width"];

    echo "<iframe src=\"" . $url . "\"" . " height=\"" . $height . "\" " . "width=\"" . $width . "\"" . " frameborder=\"0\">" . " " . "<\iframe>" . "\n";

我的输出:

<iframe src="http://192.168.86.105:3000/dashboard-solo/db/home?panelId=6" height="200" width="450" frameborder="0"> &lt;\iframe&gt;
&lt;iframe src="http://192.168.86.105:3000/dashboard-solo/db/home?panelId=7" height="200" width="450" frameborder="0"&gt; &lt;\iframe&gt;
&lt;iframe src="http://192.168.86.105:3000/dashboard-solo/db/home?panelId=11" height="200" width="450" frameborder="0"&gt; &lt;\iframe&gt;
&lt;iframe src="http://192.168.86.105:3000/dashboard-solo/db/home?panelId=4" height="200" width="350" frameborder="0"&gt; &lt;\iframe&gt;
&lt;iframe src="http://192.168.86.105:3000/dashboard-solo/db/home?panelId=8" height="200" width="450" frameborder="0"&gt; &lt;\iframe&gt;
&lt;iframe src="http://192.168.86.105:3000/dashboard-solo/db/home?panelId=10" height="200" width="450" frameborder="0"&gt; &lt;\iframe&gt;
&lt;iframe src="http://192.168.86.105:3000/dashboard-solo/db/home?panelId=3" height="200" width="450" frameborder="0"&gt; &lt;\iframe&gt;
&lt;iframe src="http://192.168.86.105:3000/dashboard-solo/db/home?panelId=5" height="200" width="350" frameborder="0"&gt; &lt;\iframe&gt;
</iframe>

What I see

1 个答案:

答案 0 :(得分:0)

检查修改后的foreach循环:

foreach ($dl as $element) {
    $url = $element["url"];
    $height = $element["height"];
    $width = $element["width"];

    echo "<iframe src=\"{$url}\" height=\"{$height}\" width=\"{$width}\" frameborder=\"0\"></iframe>\n";
}