How can I add elements in a multidimensional array?

3

How do I add elements to a multidimensional array. For example instead of creating an array in PHP like this:

$i = 0;
$aArray[$i]['title'][] = 'teste';
$aArray[$i]['link'][] = 'teste de link';

Being able to do so

$aArray[$i] = array( 'title' => ??????, 'link' => ????? ) 

o ???? should add an element to the end of this array

    
asked by anonymous 27.07.2015 / 18:07

1 answer

3

As I understand it, you should be wanting to simplify the process.

I do not know if it applies to your case, but one way to do this is by using the references - through the & sign.

$test =& $array[1]['test'];

$test[] = 'stack';

$test[] = 'overflow';

print_r($array);

Result:

Array
(
    [1] => Array
        (
            [test] => Array
                (
                    [0] => stack
                    [1] => overflow
                )

        )

)
    
27.07.2015 / 18:24