Merge the array and variables:

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
)

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.