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
    • 105
    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.

    <?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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: