Easy Tutorial
❮ Func String Str Shuffle Func Curl_Copy_Handle ❯

PHP compact() Function

Complete PHP Array Reference Manual

Example

Create an array containing variable names and their values:


Definition and Usage

The compact() function creates an array containing variable names and their values.

Note: Any strings that do not have corresponding variable names are skipped.


Syntax

Parameter Description
var1 Required. 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. Allows multiple parameters.

Technical Details

Return Value: Returns an array with all variable names and their values.
PHP Version: 4+
--- ---

More Examples

Example 1

Using strings without corresponding variable names, and an array of variable names:


❮ Func String Str Shuffle Func Curl_Copy_Handle ❯