Q:

How to store foreach results in a variable and use it in an array

I can't seem to figure this out. How can I store foreach results in a variable? Here is my code.
$ids = get_field('auction_catalog');

if($ids) {
    foreach($ids as $id => $auctionids) {
        $string .= $auctionids . ', ';
    }

    echo $string;
}

the result above is: 1,2,
but the result I want to get is: '1', '2'
I want to use the results in an array like so...
array(
    'taxonomy'=> 'auction-catalog',
    'field' => 'term_id',
    'terms' => array( $string ) // array('1', '2')
)

Thanks in advance!

A:

You currently assign it to be a single string, not elements of the array. That means that you get one element in your array with the string 1, 2,. You could explode() the string to convert it into elements in an array, but it's easier to just use an array from the beginning instead.
If you want the resulting array to be an array with the elements from $auctionids, just add them to an array that you supply to the final array, as such
$ids = get_field('auction_catalog');
$terms = array(); // Define the array

if($ids) {
    foreach($ids as $id => $auctionids) {
        $terms[] = $auctionids;
    }
}

$term is now an array, you can put directly in your other array, as such 
array(
    'taxonomy'=> 'auction-catalog',
    'field' => 'term_id',
    'terms' => $terms
)

