Merge the array and variables:
Merge the array and variables:
=======================
In php, We can merge the any number of variables and array into single array,using compact function. Compact can create an array of
containing variable and their values.
Sytax:-
====
array compact ( mixed varname [, mixed …])
It takes number of variables as parameter. Each parameter can be either a string containing the name of the variable or an array of
variable names.The array can contain other arrays of variable names inside it.Compact handles recursively
In which it will take the variable as key of the array, and variable value as the value of array element. If Any strings that are not set will simply be skipped.
Example:
======
<?php
$one = “one”;
$two = “two”;
$thfo = array(”third”,”fourth”);
$fi = “fifth”;
$result = compact(”one”,”two”,”thfo”,”fi”);
print_r($result);
?>
Array (
[one] => one
[two] => two
[thfo] => Array (
[0] => third
[1] => fourth
)
[fi] => fifth
)
