Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable in array value

Status
Not open for further replies.

webdev007

Programmer
Sep 9, 2005
168
Is there a way to achieve this
(Which of course does not work!)
I try to set a var in an array 'value'=>
for example:
array('value'=> '/aa/$my_var/cc/', 'text' => 'My TEST',)'
and more ......
);
so how can I write an array in order to include such a var in the array?

I do not figure my way around that litle problem

thanks

Regards
 
$test=array()

$test['value']="aa" . $my_var . "cc";
$test['text']="My TEST";

and to put the values in an var with the corresponding value you do

while ( list($field, $value) = each ($test))
{
$$field=$value;
}

something like this ??
 
Absolutely!

Thank you for your swift answer

that will do fine.
 
I came with the following
but I cannot find a way to make this next line working:
$lib_dir_2['value']=($lib_dir),
as is ($lib_dir), does not get its value.


using the variable variable structure

// Disregarding beginning of script
// query is fine and verified

while($data = mysql_fetch_array($result)){

$lib_dir=$data['lib_dir'];
} // echoing $lib_dir works fine.

$cfg['ilibs_dir']=array(
$lib_dir_2['value']=($lib_dir),// no data passing in $lib_dir
$lib_dir_2['text']=(' "My TEST" ')
);
while ( list($field, $value) = each ($lib_dir_2))
{
$$field=$value;
}

array was never my forte; understatement!

Thanks

Regards
 
Hello hos2,
Well I tried a whole bunch of variations
and still cannot get the value out of the $lib_dir
in:
$lib_dir_2['value']=($lib_dir),// no data passing in $lib_dir

your suggestion does not work for $lib_dir could not hang without surrounding parentheses or comma or something else?

I guess the structure of the array has an error
(not only that line but possibly the array construction?)
but cannot figure it out.
thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top