0

Hi all,

I am using a for statement to generate lots of arrays, example:

Array
(
    [0] => 2
    [1] => 395.0
    [2] => 0.33
)
Array
(
    [0] => 3
    [1] => 394.0
    [2] => 0.81
)

But, I want to have them all within 1 array, example:

Array
(
[0] 
    (
        [0] => 2
        [1] => 395.0
        [2] => 0.33
    )

[1]
    (
        [0] => 3
        [1] => 394.0
        [2] => 0.81
    )
)

Am I able to do this within my for statement, which is currently:

for ($c=0; $c < $num; $c++) 
        {
            echo '<pre>';
            print_r(str_getcsv($data[$c], ' '));
            echo '</pre>';
        }

My research online has just turned up merging or adding to arrays, not adding arrays as a seperate level like I want to here... Can anyone help?

1
Contributor
2
Replies
14
Views
1 Year
Discussion Span
Last Post by James_43
0

Update:

code now reads:

        for ($c=0; $c < $num; $c++) 
    {
            echo '<pre>';
            $finalData[] = $data[$c];
            print_r(str_getcsv($data[$c], ' '));
            echo '</pre>';
        }

And below that I've added another for statement:

for ($i = 0; $i < $num; $i++)
{
    $finalData[$i] = str_getcsv($finalData[$i]);
}

The result is:

Array
(
    [0] => Array
        (
            [0] => 1 390.49 0.01
        )
        .....

Which is closer to what I want... I imagined that the second for statement would seperate the extra data and add them as sub-arrays.

0

Solved!

for ($c=0; $c < $num; $c++) 
    {
            echo '<pre>';    
            $data[$c] = (str_getcsv($data[$c], ' '));
            $finalData[] = $data[$c];
            echo '</pre>';
        }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.