php 的 compact() 函式可以建立一個包含變數和它們的值的陣列。
語法:
compact(var1,var2...)
範例:
$firstname = "Peter"; $lastname = "Griffin"; $age = "41"; $result = compact("firstname", "lastname", "age"); print_r($result); //輸出 Array ( [firstname] => Peter [lastname] => Griffin [age] => 38 )