2017-01-18 56 views
-3

我正在使用php和html构建homelab仪表板。目前我正试图从数组中获取信息并将其显示在div中。数组中提供的信息是iframe的url以及高度和宽度调整。我的问题是如何检索此数组的特定元素,以便我可以正确显示它。如何使用PHP检索多维数组的特定元素

$dl = [ 
    'dashlet1' => [ 
     'url' => 'some random url', 
     'height' => 'height=200', 
     'width' => 'width=450' 
    ], 
    'dashlet2' => [ 
     'url' => 'another random url', 
     'height' => 'height=200', 
     "width" => 'width=450' 
    ], 
    'dashlet3' => [ 
     'url' => 'another random url', 
     'height' => 'height=200', 
     'width' => 'width=450' 
    ], 
    'dashlet4' => [ 
     'url' => 'another random url', 
     'height' => 'height=200', 
     'width' => 'width=350' 
    ], 
    'dashlet5' => [ 
     'url' => 'another random url', 
     'height' => 'height=200', 
     'width' => 'width=450' 
    ], 
    'dashlet6' => [ 
     'url' => 'another random url', 
     'height' => 'height=200', 
     'width' => 'width=450' 
    ], 
    'dashlet7' => [ 
     'url' => 'another random url', 
     'height' => 'height=200', 
     'width' => 'width=350' 
    ], 
    'dashlet8' =>[ 
     'url' => 'another random url', 
     'height' => 'height=200', 
     'width' => 'width=450' 
    ] 

]; 
+0

http://php.net/manual/en/control-structures.foreach.php – AbraCadaver

+0

开始读一本手册和[MCVE] –

+0

为了得到一个特定的元素,例如,'$ DL ['dashlet6 '] [' URL']'。 [请参阅数组文档](http://php.net/manual/en/language.types.array.php#language.types.array.syntax.accessing)。 –

回答

0

可以说你想访问的网址。您可以通过执行

echo $dl['dashlet1']['url']; 
echo $dl['dashlet2']['url']; 

你也可以使用一个循环做到这一点。

foreach($dl as $key => $value) { 

     echo($key . " " . $value['url']); 
    }