How to conditionally push a child row into a subarray
17:07 23 Jun 2013

I have an array like this:

$testflag = '';

$test = array(
    'auxiliaryFields' => array(
        array(
            'key'   => 'extra1',
            'label' => 'TEST',
            'value' => 'TEST',
            'textAlignment' => 'PKTextAlignmentLeft'                
        )
        if ($testflag != '') {
        ,
        array(
            'key'   => 'extra2',
            'label' => 'TEST2',
            'value' => 'TEST2',
            'textAlignment' => 'PKTextAlignmentLeft'                
        )
    }
));
var_dump($test);

Now, I've read that you can't use code inside an array, so my question is how to do the above? In this example it's just 2 arrays (extra1 & extra2) but I have 4 arrays in total in my actual code. The condition is basically if session:form:element:not_null then include extra2 - 3 - 4 and so on, if it IS null, do nothing.

Can someone please help?

php arrays if-statement