如何使用键值对php创建多维数组

时间:2013-02-19 11:37:46

标签: php multidimensional-array

我有两个这样的数组:

数组1在数组

中的数组y轴值中具有x轴值
x-array: ["04 Feb","05 Feb","06 Feb","07 Feb","08 Feb","09 Feb","10 Feb"]
y-array: [3.27,3.34,3.27,3.2,3.28,3.17,3.15]

Array2在数组

中的数组y轴值中具有x轴值
x-array2: ["11 Feb", "12 Feb"]
y-array2: [3.19, 3.36]

如何使用键值对创建多维数组。

如下面的php

Array
(
    [0] => Array
        (
            [x-axis] => Array
                (
                    [0] => 04 Feb
                    [1] => 05 Feb
                    [2] => 06 Feb
                    [3] => 07 Feb
                    [4] => 08 Feb
                    [5] => 09 Feb
                    [6] => 10 Feb
                )

            [y-axis] => Array
                (
                    [0] => 3.27
                    [1] => 3.34
                    [2] => 3.27
                    [3] => 3.2
                    [4] => 3.28
                    [5] => 3.17
                    [6] => 3.15
                )

        )

    [1] => Array
        (
            [x-axis] => Array
                (
                    [0] => 11 Feb
                    [1] => 12 Feb
                )

            [y-axis] => Array
                (
                    [0] => 3.19
                    [1] => 3.36
                )

        )

)

2 个答案:

答案 0 :(得分:1)

$array = array(
  0 => array(
    "x-axis" => $x_array,
    "y-axis" => $y_array),
  1 => array(
    "x-axis" => $x_array2,
    "y-axis" => $y_array2)
) ;

var_dump($array) ;

答案 1 :(得分:1)

$new_array = array(array("x-axis"=>$x-axis-array,
                         "y-axis"=>$y-axis-array
                        ),
                   array("x-axis"=>$x-axis-array2,
                         "y-axis"=>$y-axis-array2
                        )
                  );

echo "<pre>";
print_r($new_array);