Yesterday I was looking for a method how I can get or extract one String from a PHP application.

I wanted to find out that there is some variable in the web page (or may be more than one variable)

and they are having their associated values.

Now I have to find out whether there is the variable in my case  no_of_comment and if it is there then what are the values associated  with them.

As a solution I got a nice function in php.net,

extract(array_variable,extract_type,prefix_value)

here, array_variable is an array or a key value pair, where keys are treated as variable name and values as variable values.

extract_type: this determines what to do if  there is more than one value or there is no variable in that name at  all. means how the value to be taken to the out put.

prefix_value: this is to determine the default value which is given adding one underscore with the variable name.

Here is how it worked for me

<?php
$comment = “this is for getting the values “;
$var_array = array(“name” => “estimatingFunction”,
“type” => “humanNurology”,
“$comment” => “estimating the road crossing”);
extract($var_array,EXTR_PREFIX_SAME,”page”);
echo “$name,$type,$comment,$page_comment\n”;
?>

out put:

estimatingFuction,humanNurology,estimating the road crossing, this is for getting the values.

extract converts all the arrays and key value pairs to a list of  variables and there values. Here the page is global variable so comment  associated with this is the first comment, and gives the out put as the  first comment.

thanks