Reply to Re: FUSK!

Your name:

Reply:


Posted by J.O. Aho on 01/09/07 10:18

Onideus Mad Hatter wrote:
> In PHP...how you do you have a variable, array variable?
>
> Like I have an array called $line_1 all the way through $line_192
>
> And so I want to have a while statement where I've got like:
>
> $i = 1
> $pos = 5
>
> And then do it like $line_$i[$pos]
>
> Cept it doesn't work. Neither does $line_[$i][$pos]

For that to work, you had to had made a multidimensional array, which had most
likely been the easiest for you.

or
> $line_($i)[$pos] or $line_'$i[$pos]' or any of the other combinations
> and variations I've tried.

All those are really meaningless tries, you are still trying to add together
the variable $line_, $i and $pos.

This is how you have to do it, you save the variable name you want to use into
a string and from there use it, not completely sure which will be the right
"syntax", but you can try.

--- first ---
$variabletouse="line_$i";
echo $$variabletouse[$pos];
--- eof ---

--- second ---
$variabletouse="line_$i[$pos]";
echo $$variabletouse;
--- eof ---

Notice the double $ in front of the variable, this makes PHP to use the string
as the variable name.


--

//Aho

[Back to original 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

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