UK[kəmˈpækt] US[ˈkɑ:mˈpækt]

vt.& vi. Press, (make) solid; make... tight, make... strong; make (style) concise, simplify; become compact, become strong

adj. compact; concise, (style, etc.) compact; small and easy to carry; (material) dense, (physical) strong

n. Agreement; treaty; small compact with mirror; car

Third person singular: compacts Present participle: compacting Past tense: compacted Past participle: compacted

php compact() function syntax

Function:Create an array containing variable names and their values

Syntax: compact(var1,var2...)

Parameters:

##var1Required. Can be a string with a variable name, or an array of variables. var2,...Optional. Can be a string with a variable name, or an array of variables. Multiple parameters are allowed.
ParametersDescription

Description: Create an array containing variable names and their values. Any string that does not have a corresponding variable name is ignored.

php compact() function example

<?php
$firstname = "西门";
$lastname = "灭绝";
$age = "25";
$result = compact("firstname", "lastname", "age");
print_r($result);
?>

Run instance»

Click the "Run instance" button to view the online instance

Output:

Array ( [firstname] => 西门 [lastname] => 灭绝 [age] => 25 )


<?php
$name = "无忌";
$job = "讲师";
$age = "20";
$result = compact("name", "job", "age");
print_r($result);
?>

Run Instance»

Click the "Run Instance" button to view the online instance

Output:

Array ( [name] => 无忌 [job] => 讲师 [age] => 20 )