PHP Programing language

array_compact() Function in PHP
Previous Home Next

array_compact()

The compact() function creates an array from variables and their values.

Syntax:
compact(var1,var2...)

In above syntax, "var1" can be a string with the variable name, or an array of variables and "var2,..." can be a string with the variable name, or an array of variables. Multiple parameters are allowed.

Example:

<?php
$firstname = "Albert";
$lastname = "Smyth";
$age = "56";
$result = compact("firstname", "lastname", "age");
print_r($result);
?>

Output:

Array ( [firstname] => Albert [lastname] => Smyth [age] => 56 )

Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: