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?

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.

Solved!

for ($c=0; $c < $num; $c++) 
    {
            echo '<pre>';    
            $data[$c] = (str_getcsv($data[$c], ' '));
            $finalData[] = $data[$c];
            echo '</pre>';
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.