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

See also https://gist.github.com/Ocramius/c56a8e8ff25a8e0bd96800c41edab02a

Related : extract(), Variable Variables