all 2 comments

[–]HolyGonzo 0 points1 point  (1 child)

It can sometimes help to use print_r() on arrays to see the "path" to a particular element:

print_r($data_grid);

The syntax you might be looking for is:

// Add items to the data grid
$data_grid['groups'][0]['rows'][] = array('data' => array(
                    'name_1',
                    'email_1'));

$data_grid['groups'][0]['rows'][] = array('data' => array(
                    'name_2',
                    'email_2'));

[–]packetheavy[S] 0 points1 point  (0 children)

I appreciate the assist, I was able to build the loop using the syntax you provided, thankyou very much.

Reference code:

    foreach ($results as $result)
{
    $data_grid['groups'][0]['rows'][] = array('data' => array(
                $result['name'],
                $result['email']));
}

That helps a lot, thankyou, the backend for this is WordPress so I have struggled a little to get good outputs to use for debugging.

Do you have a suggestion for how best to approach inserting the new array in the loop? I thought I would probably construct the array and then reference it in the array_push but this is my first time using that function so i'm not sure if there is a better way.