Page 1 of 1

Array Help

Posted: Fri Aug 10, 2007 1:30 pm
by icesolid
I want to make array values and then put them into the array. I am having problems however.

Here is the array I want to use:

Code: Select all

$month_array = "January, February, March, April, May, June";
$month_total_array = "Cases Ordered in 2006 ($customer), 100, 120, 150, 170, 180, 190";

$chart["chart_data"] = array(array($month_array), array($month_total_array));
Here is the array that will work:

Code: Select all

$chart["chart_data"] = array(array("January", "February", "March", "April", "May", "June"),          array("Cases Ordered in 2006 ($customer)", 100, 120, 150, 170, 180, 190));

Posted: Fri Aug 10, 2007 1:57 pm
by Jaxolotl
I think the problem is here

Code: Select all

$chart["chart_data"] = array(array($month_array), array($month_total_array));
You are calling the funtion array on a string ($month_array = "January, February, March, April, May, June"; ) It seems quiet strange

Maybe you want to do somthing linke this

Code: Select all

$chart['chart_data'] = array(explode(",",$month_array), explode(",",$month_total_array));
His is the output you have with explode()

Code: Select all

Array
(
    [0] => Array
        (
            [0] => January
            [1] =>  February
            [2] =>  March
            [3] =>  April
            [4] =>  May
            [5] =>  June
        )

    [1] => Array
        (
            [0] => Cases Ordered in 2006 ()
            [1] =>  100
            [2] =>  120
            [3] =>  150
            [4] =>  170
            [5] =>  180
            [6] =>  190
        )

)
By writing the code as you did you'll obtain

Code: Select all

Array
(
    [0] => Array
        (
            [0] => January, February, March, April, May, June
        )

    [1] => Array
        (
            [0] => Cases Ordered in 2006 (), 100, 120, 150, 170, 180, 190
        )

)

Posted: Fri Aug 10, 2007 2:07 pm
by Jaxolotl
another way to do it would be

Code: Select all

$month_array = array("January", "February", "March", "April", "May", "June");
$month_total_array = array("Cases Ordered in 2006 ($customer)", "100", "120", "150", "170", "180", "190");

$chart["chart_data"] = array($month_array, $month_total_array);
mean setting $month_array and $month_total_array as an array when declaring it.
I think this would be better because In the first example I use the "," as boundary but maybe theres is an unespected "," on the $customer var that will make output unpredictable

With this code output is still

Code: Select all

Array
(
    [0] => Array
        (
            [0] => January
            [1] => February
            [2] => March
            [3] => April
            [4] => May
            [5] => June
        )

    [1] => Array
        (
            [0] => Cases Ordered in 2006 ()
            [1] => 100
            [2] => 120
            [3] => 150
            [4] => 170
            [5] => 180
            [6] => 190
        )

)