How to use compact in PHP
In this article, I will explain how the compact() function can be used in PHP.
compact() function in PHP
- The compact() function is used to creates an array from variables and it's values.
- In compact() function, each parameter can be either a string containing the name of the variable, or an array of variable names.
- The compact() function are allowed Multiple parameters.
Syntax
Parameter
- val1 val1 is required parameter. it can be a string with the variable name, or an array of variable.
- val2 val2 is optional parameter. it's same as val1.
Example
The following example show to how the compact() function can be used in PHP.
<html>
<body>
<h3 style="color: blueviolet;">compact() function example in PHP</h3>
<?php
$fname = "Nitin".'</br>';
$lname = "Bhardwaj".'</br>';
$age = "22".'</br>';
$result = compact("fname", "lname", "age");
print_r($result);
?>
</body>
</html>
|
Output
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here