Create an array from variables and their values in PHP

Description

The following code shows how to create an array from variables and their values.

Example


//from ww w.j a v  a2s .c o m
<?php
    $firstname = "XML";
    $lastname = "HTML";
    $age = "41";

    $result = compact("firstname", "lastname", "age");

    print_r($result);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone