Get an array of ids from a collection of pages

How is it possible to get an array of ids from a collection of pages ?

for exemple:

from an $elements collection of pages


I would like an array like the one I get from a structure field:


Loop through the collection and add the UIDs to an array.

$uids = array();
foreach(page('path_to_section-one')->children() as $p) {
  $uids[] = $p->uid();

Or even easier:

$uids = page('path_to_section-one')->children()->pluck('uid');

that’s almost what I want. Let me bring more context.

In a snippet I use a function that loops over a stuctured field that way:

$cards = new Pages();
foreach($elements as $element) {

The snippet is called like this:

snippet('cards', array('elements' =>  $page->elements()->toStructure() ));

Now, I would like to use the same snippet from another page where elements does not come from a structured field but from a pages collection. Is there a way to make this page collection look like a structured field, where the uid of each page is associated with a name key?

I found a solution: I made two snippet, one for the structured field, one for the pages collection. The former process the structure fields and build a page collection then call the latter. thanks for your quick answer.