将变量名和内容保存到php中的关联数组中

Can i define an associative array using name and value of some variables at the same time and without looping in a simple elegant way?

I know it is possible taking variable names or setting it manually is not hard at all, but i think there might be a function to do this all at once. Or there should be one, but i didnt found any

Im looking a function similar to:

$ar_var= to_associative_array($name, $id, $start_date, $end_date, $status, $details);

... and being able to print something like:

echo $ar_var['status'];
echo $ar_var[5];//Usually you would use this to access this data

... or a vardump showing something like

name => 'John Doe'
id => 'FX1678798Z'
start_date = > '27/03/2018'
status => 'delivered'

You can use compact() to accomplish this.

Assuming the variables you are using are declared and have assigned values, you can use it like this:

$ar_var = compact('name', 'id', 'start_date', 'end_date', 'status', 'details');

Example: https://3v4l.org/8jnCe