0

我已将 SQL 数据加载到一堆数组中。我想用这些数组来创建一个大的多维数组。

for ($h=0; $h<=count($siteName); $h++){

    for ($x=0; $x<=count($pluginNames); $x++)
    {
        for ($y=0; $y<=count($wpvData); $y++)
        {
            $plugData = array($siteName[$h]=>array($pluginNames=>array($pluginNames[$x],$vData[$y],$wpvData[$y],$row[$y])));
        } 
    } 
}

我得到的错误是:

Notice: Undefined offset: 0 in /Applications/MAMP/htdocs/BJANSDJNAS.php on line 124

Warning: Illegal offset type in /Applications/MAMP/htdocs/BJANSDJNAS.php on line 124

第 124 行 = $plugData 数组行。

这甚至可能吗?

有没有更好的方法可以一起完成这一切?

我的目标是将一堆与网站相关的数据存储在多维数组中,以便我可以在 html div 中显示它。基本上我有一个 wordpress 网站,我想通过 html 用漂亮的 GUI 管理插件。

4

1 回答 1

1

What you want is probably something like this:

$plugData = array();
foreach ($siteName as $site) {
    $plugData[$site] = array();
    foreach ($pluginNames as $plugin)
        $plugData[$site][$plugin] = array();
        foreach ($wpvData as $y => $wpv) {
            $plugData[$site][$plugin][] = array(
                'plugin' => $plugin,
                'vdata' => $vdata[$y],
                'wpv' => $wpv,
                'row' => $row[$y]);
        }
    }
}

Notice that the syntax for adding an element to an array is $arrayname[] =; $arrayname = simply replaces the whole array, it's not something you usually want in a loop.

于 2013-10-01T16:53:40.057 回答