PHP: merge 3 tables per index into a multidimensional array

advertisements

I'm starting with PHP and I this is the moment when I stuck on an array merging conundrum.

I got 3 arrays:

t1 Array
(
    [0] => I
    [1] => You
    [2] => She

)

t2 Array
(
    [0] => am
    [1] => are
    [2] => is

)

t3 Array
(
    [0] => confused
    [1] => great
    [2] => awesome

)

I would like to merge them in a way which will give me the result as below:

$result = array (
        array( 'I', 'am', 'confused' ),
        array( 'You', 'are', 'great' ),
        array( 'She', 'is', 'awesome' ),
);

The problem is that each array (t1, t2, t3) can accomplish different number of values (the data is taken from uploaded file). For sure every time the numbers of values for t1, t2 and t3 will be equal. I just can't figure it how to do this. Can you please give me a hint?


Demonstrating SPL's MultipleIterator:

$t1 = array( 'I', 'You', 'She' );
$t2 = array( 'am', 'are', 'is' );
$t3 = array( 'confused', 'great', 'awesome' );

$mi = new MultipleIterator();
$mi->attachIterator(new ArrayIterator($t1));
$mi->attachIterator(new ArrayIterator($t2));
$mi->attachIterator(new ArrayIterator($t3));
$newArray = array();
foreach($mi as $details) {
    $newArray[] = $details;
}
var_dump($newArray);