简体   繁体   English

关联数组和格式问题

[英]Issues with associative array and formatting

I've been attempting to create a dashboard with grafana embedded graphs. 我一直在尝试创建具有grafana嵌入式图形的仪表板。 I've had some problems with formatting them which I believed was something I was coding incorrectly but after investigating and creating a different post about it here I've confirmed that this should and does output correctly all of my dashlets. 我在格式化它们时遇到了一些问题,我认为这是我编码不正确的问题,但是在这里调查并为此撰写了另一篇文章后,我已经确认这应该并且确实能输出所有仪表板。 My problem is that it is not displaying them, instead its only displaying the first one inside the array. 我的问题是它不显示它们,而是仅显示数组中的第一个。

My code: 我的代码:

/*
 * 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";

My output: 我的输出:

<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 我所看到的

Check modified foreach loop: 检查修改的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";
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM