array_column() reshapes query rows into one column as a list, or keyed by another column, such as prices by product id. array_keys(), array_values() and array_combine() split and rejoin keys and values, and range(), array_fill(), array_fill_keys() and array_pad() generate arrays.
<?php
$rows = [['id' => 1, 'title' => 'Dune', 'price' => 9.99], // as fetched from products
['id' => 2, 'title' => 'Emma', 'price' => 4.5]];
echo json_encode(array_column($rows, 'title')), ' ',
json_encode(array_column($rows, 'price', 'id')), ' ', // id => price
json_encode(range(0, 20, 5)), ' ', json_encode(array_fill_keys(['SF', 'Poetry'], 0)), "\n";
$x = ['cur' => 'USD', 5 => 'a'];
$y = ['cur' => 'EUR', 5 => 'b'];
echo json_encode(array_merge($x, $y)), ' ', json_encode(array_replace($x, $y)), "\n";
$title = 'Dune';
echo json_encode(compact('title')), ' '; // variables -> array
extract(['title' => 'Overwritten?', 'currency' => 'USD'], EXTR_SKIP); // array -> variables
echo "$title $currency\n";["Dune","Emma"] {"1":9.99,"2":4.5} [0,5,10,15,20] {"SF":0,"Poetry":0}
{"cur":"EUR","0":"a","1":"b"} {"cur":"EUR","5":"b"}
{"title":"Dune"} Dune USDarray_merge() lets a later string key win but renumbers integer keys, so both 5 => ... elements survive; array_replace() keeps every key and takes the later value, and array_merge_recursive() gathers clashing values into an array. compact() builds an array from named variables and extract() does the reverse. Never extract($_POST), which lets a visitor overwrite any variable in scope; pass EXTR_SKIP so existing variables win.