Forum Moderators: coopster

Message Too Old, No Replies

Passing a var value in array

This uses variable-variable

         

henry0

11:04 am on Oct 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This array uses a variable-variable
but I cannot pass in the array $lib_dir value
A) is it doable
B) I tried any variations I can think of to pass $lib_dir but the good one!

$lib_dir=$data['lib_dir'];// the query and above script works fine (verified)
}

$cfg['ilibs_dir']=array(
$lib_dir_2['value']=('$lib_dir'), // Cannot get $lib_dir value , although as a stand alone out of the array it echoes OK.
$lib_dir_2['text']=(' "My TEST" ')
);
while ( list($field, $value) = each ($lib_dir_2))
{
$$field=$value;
}

mcibor

3:01 pm on Oct 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You cannot put variables in single quotes!

This is the correct version

$lib_dir = $data['lib_dir'];// the query and above script works fine (verified)
}

$cfg['ilibs_dir'] = array(
($lib_dir_2['value'] = $lib_dir), // Cannot get $lib_dir value , although as a stand alone out of the array it echoes OK.
($lib_dir_2['text'] = 'My TEST')
);
while ( list($field, $value) = each ($lib_dir_2))
{
$$field = $value;
}

Hope this helps!
Michal Cibor

henry0

6:05 pm on Oct 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Michal,
Well, sorry to report that it does not pass its value to the array.

unfortunately I have for the rest of the script no other alternative than to pass it inside the array
($lib_dir_2['value'] = $lib_dir),
I can live with a stripped out version
without "While"
and simply trying to pass $lib_dir within an array
$cfg['ilib_dir']=array(
and then within the array $lib_dir)
so via the array
$cfg['ilib_dir'] will have $lib_dir value.

coopster

6:42 pm on Oct 25, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



henry0, you have a variable named the same as the index value in your while loop that is giving you problems, change the variable named "$value" to something other than one of your array's indexes ;)

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

coopster

8:17 pm on Oct 25, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



So when you use it as a variable variable, you are grabbing the wrong variable. Does that make sense?

henry0

8:56 pm on Oct 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes Thank you, I see what was wrong!
I understand the var var concept
It opens many doors

So much knowledge to grab :)
like the stored procedure avail with the new MySQL
but I have seen that you were there earlier.

BTW
GLITCH
I do not get forum answer notifications>