Posted by tihu on 05/05/06 20:53
ImOk wrote:
> I come from the Visual Foxpro world, which is one reason I love PHP.
> VFP is a scripting type language with macro substitution abilities
> similar to PHP.
>
> Besides the regular expansion I can do crazy things (VFP uses & instead
> of $):
>
> x="sales"
> sales="1000"
> salestax="8.25"
> ? &x
> .........prints 1000
> ? &x.tax
> ...........prints 8.25
>
> tr="trim"
> ? &tr.("xxx ")
> .........prints xxx
>
> ? 'This function is &tr.("xxxxx ")'
> ...... prints This function is trim("xxxxx ")
>
> In VFP the & indicates macro expansions and a space or a . idnicates
> the variable termination. Can I do this kind of partial expansion in
> PHP? There must be a trick somewhere.
>
> Thanks.
Variable variables might be what you are looking for, they use $$
instead of $
http://www.php.net/manual/en/language.variables.variable.php
Basically
$name = 'joe';
$getvar = 'name'
echo $$getvar; //prints $name so the output is 'joe'
It works with functions and class methods too
$tr = 'trim'
echo $tr(' xxxxx '); // calls the function trim() and prints
xxxx
Seeya
Tim
[Back to original message]
|