AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
#### 定义和用法 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 ) ~~~