如何将此代码转换为循环以简化它?

How can I simplify this code as a loop? Do i need to use a foreach loop inside the loop too?

foreach ($data as $item) {
    $a = new stdClass;
    $a->v = $item->location_name;
    $a->f = null;

    $b = new stdClass;
    $b->v = intval($item->count);
    $b->f = null;

    $c = new stdClass;
    $c->c = array($a, $b);

    $rows[] = $c;
}

Looks like you could more simply use array_map and some array-to-object casting

$rows = array_map(function($item) {
    return (object) ['c' => [
        (object) ['v' => $item->location_name, 'f' => null],
        (object) ['v' => intval($item->count), 'f' => null]
    ]];
}, array_values($data));