You have a 1 dimensional array of objects, instances of stdClass, to be exact:
Array
(
[0] => stdClass Object //<== stdClass OBJECT!!
That means that you can either use the objects, and access the names like you would with any object:
foreach ($array as $row)
{
echo $row->name, PHP_EOL;
}
Or, if you really want to, you can simply cast the objects to arrays:
foreach ($array as $k => $o)
{
$array[$k] = (array) $o;//cast and re-assign
}
Next time you loop over the $array, the objects will be gone, and you'll get associative arrays instead... really, though, this cast business is just overhead, I'd really just use the objects if I were you.
Of course, if you can change the fetch mode, you could change it so that all results are fetched as associative arrays.
According to the wordpress documentation, you can pass a second argument to the get_results method, that specifies the fetch method:
$r2 = $wpd->get_results($q2, ARRAY_A);
Would be the best way to ensure that $r2 is actually an array of associative arrays
To quote the documentation on which I base this:
Generic, mulitple row results can be pulled from the database with get_results. The function returns the entire query result as an array, or NULL on no result. Each element of this array corresponds to one row of the query result and, like get_row, can be an object, an associative array, or a numbered array.
<?php $wpdb->get_results( 'query', output_type ); ?>
query
(string) The query you wish to run. Setting this parameter to null will return the data from the cached results of the previous query.
output_type
One of four pre-defined constants. Defaults to OBJECT. See SELECT a Row and its examples for more information.
OBJECT - result will be output as a numerically indexed array of row objects.
OBJECT_K - result will be output as an associative array of row objects, using first column's values as keys (duplicates will be discarded).
ARRAY_A - result will be output as an numerically indexed array of associative arrays, using column names as keys.
ARRAY_N - result will be output as a numerically indexed array of numerically indexed arrays.
ObjectNot anArray... As @EliasVanOotegem says...