compact()

compact() is a native PHP function, which creates an array containing variables and their values.

It is the opposite of extract().

<?php

$a = '1';
$b = '2';

$array = compact('a', 'b');
// ['a' => 1, 'b' => 2];
?>

Documentation

Related : extract(), Variable Variables