over 9 years ago
What is compact() Function ?
compact() Function is used for creating an array from variables and their values.
Syntax compact() Function:
compact(variable1,variable1,variable3....)
Note:If any strings that does not match variable names will be skipped.
You can take reference form below example to use of compact() function.
- <?php
- $Emp_name = "Jorden";//here $Emp_name is a variable name
- $Emp_cityname = "addor";//here $Emp_cityname is a variable name
- $age = "41";//here $age is a variable name
- $zip_code = "220011";//here $zip_code is a variable name
- //here call compact()
- $Emp_detail = compact("Emp_name", "Emp_cityname", "age","zip_code");
- //now print the Emp_detail
- print_r($Emp_detail);
- ?>
<?php $Emp_name = "Jorden";//here $Emp_name is a variable name $Emp_cityname = "addor";//here $Emp_cityname is a variable name $age = "41";//here $age is a variable name $zip_code = "220011";//here $zip_code is a variable name //here call compact() $Emp_detail = compact("Emp_name", "Emp_cityname", "age","zip_code"); //now print the Emp_detail print_r($Emp_detail); ?>
ouptput will come following:
Array ([Emp_name] => Jorden [Emp_cityname] => addor [age] => 41 [zip_code] => 220011)
0 Comment(s)