You are here: Re: Partial macro expansion of variable and function name. « PHP Programming Language « IT news, forums, messages
Re: Partial macro expansion of variable and function name.

Posted by tihu on 05/05/06 21:16

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

Just noticed the &$.tax thingy, neat trick..

In php you need to use the dot operator( joins two strings together)
and curly braces ( Think of it like php interprets the contents of {}
as an expression)
http://uk.php.net/manual/en/language.types.string.php#language.types.string.syntax.complex

$x = 'sales'
$sales = 1000;
$salestax = 8.25;

echo $$x; //prints 1000
echo ${$x.'tax'}; //prints 8.25

but
echo $$x.'tax'; // without {} it prints 1000tax

Tim

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация