0

I have two arrays like this :

Array 1 is having x-axis values in array y-axis values in array

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 is having x-axis values in array y-axis values in array

x-array2: ["11 Feb", "12 Feb"]
y-array2: [3.19, 3.36]

How to create multidimensional array with key value pair.

Like below in 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
  • 1
    whats wrong with 12 Feb? Commented Feb 19, 2013 at 11:43
  • @Bhavik Shah missed it while pasting..... Commented Feb 19, 2013 at 11:45

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

Comments

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) ;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.