|
Posted by Christoph Burschka on 04/23/07 10:08
Christoph Burschka schrieb:
> Boris Savc schrieb:
>
>> Sorry for confuzing subject, but that's the thing I'm trying to
>> achieve. For example:
>>
>> $a = "Hello";
>> $b = 1;
>>
>> I want to change the name of $a to $a1 where 1 is value of variable $b!
>>
>> Thanks for all the help,
>> Boris
>>
>
> A brief note: Something tells me you should take a programming class in
> a real language. PHP lets you do things no sane programmer would, so if
> you get used to, say, Java first, you won't want to "rename variables"
> or use strings as variable names, but follow good practices and use, for
> example, arrays.
>
> But since you're asking, and since it's possible:
>
>
> Code:
>
> $a = "Hello";
> $b = 1;
> $newname="$a$b";
> $$newname=$a;
> print $a1;
> --------------------------
>
> Will output:
>
> Hello
>
>
> --
> cb
Correction: $newname="$a$b"; is wrong, that would make the new variable
$Hello1. It should, of course, be $newname="a$b" (no $ before a), so the
new variable will be $a1.
--
cb
Navigation:
[Reply to this message]
|