💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
#### 定义和用法 compact() 函数创建包含变量名和它们的值的数组。 注释:任何没有变量名与之对应的字符串都被略过。 #### 语法 compact(var1,var2...) ~~~ <?php $firstname = "Bill"; $lastname = "Gates"; $age = "60"; $result = compact("firstname", "lastname", "age"); print_r($result); ?> ~~~ 输出 ~~~ Array ( [firstname] => Bill [lastname] => Gates [age] => 60 ) ~~~ #### 范例 Example #1 compact() 例子 ~~~ <?php $city = "San Francisco"; $state = "CA"; $event = "SIGGRAPH"; $location_vars = array("city", "state"); $result = compact("event", "nothing_here", $location_vars); print_r($result); ?> ~~~ 以上例程会输出: ~~~ Array ( [event] => SIGGRAPH [city] => San Francisco [state] => CA ) ~~~