Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use compact() Function in php ?

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 109
    Comment on it

    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.

    1. <?php
    2.  
    3. $Emp_name = "Jorden";//here $Emp_name is a variable name
    4. $Emp_cityname = "addor";//here $Emp_cityname is a variable name
    5. $age = "41";//here $age is a variable name
    6. $zip_code = "220011";//here $zip_code is a variable name
    7. //here call compact()
    8. $Emp_detail = compact("Emp_name", "Emp_cityname", "age","zip_code");
    9. //now print the Emp_detail
    10. print_r($Emp_detail);
    11.  
    12. ?>

    ouptput will come following:

    Array ([Emp_name] => Jorden [Emp_cityname] => addor [age] => 41 [zip_code] => 220011)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: