php compact() function
Translation results:
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() functionsyntax
Function:Create an array containing variable names and their values
Syntax: compact(var1,var2...)
Parameters:
Parameters | Description |
Required. Can be a string with a variable name, or an array of variables. | |
Optional. Can be a string with a variable name, or an array of variables. Multiple parameters are allowed. |
Description: Create an array containing variable names and their values. Any string that does not have a corresponding variable name is ignored.
php compact() functionexample
<?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 )
Popular Recommendations
- JVC reveals new RS2200 and RS1200 compact native 4K projectors
- Lenovo showcases its new compact Legion gaming tablet with a matte black finish
- Samsung Galaxy S25 revealed to be keeping compact flagship form factor with even thinner bezels
- Beelink SER9: Compact AMD Zen 5 mini-PC announced with Radeon 890M iGPU but limited eGPU options
- Pocket Mini: Retroid seeks to dethrone compact gaming handheld kings with new Qualcomm Snapdragon and AMOLED-based release
- Pocket Mini: Retroid seeks to dethrone compact gaming handheld kings with new Qualcomm Snapdragon and AMOLED-based release