Extract and compact

Extract and compact

int extract (array var_arr)

stores all the values in the array into symbol table with the key of the array
as variable name and value as value of the corresponding variable.

<?php

$array = array(’ab’=>’hai’);

extract($array);

echo $ab;
//// will output hai

?>

int compact(mixed varname)

which is the reverse process of compact .
It takes the string containing variable name as parameter and convert it
into an array with variable name as key and value as its value

<?php

$fname = “Jhon”;
$lname = “Rubin”;
$age = “25″;

$ar_str = array (”fname”, “lname”);

$result = compact ($ar_str);

print_r($result);

?>

will output

Array
(
[fname] = Jhon
[lname] = Rubin
[age] = 25
)

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.