PHP动态数组列表

时间:2016-03-02 10:13:35

标签: php

请有人帮我提供一个解决方案来制作一个数组的字符串列表,如:

$string=array1, array2, .........., arrayn.

我需要动态生成此列表。 现在我发送列表中的每个数组,但我想增加数字,我想知道如何动态地将数组放入列表中。

在我的代码中,我有类似的东西:

$array[$j]

我需要创建一个这样的列表:

$string=$string.','.$array[$j]

......但它不起作用。我无法将其作为多维数组发送。

有没有人有任何想法?

2 个答案:

答案 0 :(得分:0)

如果你在谈论一个多维数组:

   <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar" />

然后例如$container[0] = $string; $container[1] = $array; $container[2] = $my_other_array; // ... 将包含您的$container[1]$array,您可以访问原始数组中的密钥$container[1][$j]

答案 1 :(得分:0)

我的代码是

 $Copii = [];
        $Config_Camere = [];
        $nrCamere = $array['Camere'];
        for ($i = 1; $i <= $nrCamere; $i++) {
            if ($array['Copii_Cam' . $i] >= 1) {
                for ($j = 1; $j <= $array['Copii_Cam' . $i]; $j++) {
                    $Copii[$j] = array_combine(['AgeQualifyingCode', 'Count', 'Age'], ['c', '1', $array['varstaCopil' . $j . '_Cam' . $i]]);
                }
                if ($array['Copii_Cam' . $i] == 2) {
                    $Config_Camere['RoomRequest'] = ['IndexNumber' => $i, 'GuestsCount' => ['GuestCount' => [['AgeQualifyingCode' => 'a', 'Count' => $array['Adulti_Cam' . $i]], $Copii[1], $Copii[2]]]];
                } else if ($array['Copii_Cam' . $i] == 1) {
                    $Config_Camere['RoomRequest'] = ['IndexNumber' => $i, 'GuestsCount' => ['GuestCount' => [['AgeQualifyingCode' => 'a', 'Count' => $array['Adulti_Cam' . $i]], $Copii[1]]]];
                }
            } else {
                $Config_Camere['RoomRequest'] = ['IndexNumber' => $i, 'GuestsCount' => ['GuestCount' => ['AgeQualifyingCode' => 'a', 'Count' => $array['Adulti_Cam' . $i]]]];
            }
        }

如果你看到我想生成dinamicaly数组$ Copii 非常感谢