How to use compact function in php

<?php
$firstname = "Karthikeyan";
$lastname = "Manivasagam";
$age = "27";

$name = array("firstname", "lastname");
$result = compact($name, "location", "age");

print_r($result);
?>

Output 

 

Array ( [firstname] => Karthikeyan [lastname] => Manivasagam [age] => 27 )