Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP compact() Function

PHP compact() Function

PHP Array ReferenceComplete PHP Array Reference Manual

Example

Create an array containing variable names and their values:

Run Example »


Definition and Usage

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

**Note:** Any string that does not match a variable name is skipped.


Syntax

compact(

var1,var2...

)

Parameters 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. Multiple arguments are allowed.

Technical Details

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

More examples

Example 1

Using a string with no matching variable name, and an array of variable names:

Run Example »


PHP Array ReferenceComplete PHP Array Reference Manual