Re: [PHP] Variable Question
On 04/19/2012 09:55 AM, Christoph Boget wrote: >> I am trying to use this while look to assign them to variables: >> $word_1 >> $word_2 >> $word_3 >> ... >> $word_25 > > This should work for you: > > http://us3.php.net/manual/en/function.extract.php > > thnx, > Christoph Yes and you can use array_map('stripslashes', $row) prior. However I would just use the $row array as most people do instead of extracting. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable Question
> I am trying to use this while look to assign them to variables: > $word_1 > $word_2 > $word_3 > ... > $word_25 This should work for you: http://us3.php.net/manual/en/function.extract.php thnx, Christoph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable Question
On 19 Apr 2012, at 15:46, Ron Piggott wrote: > I am trying to assign variables from an array into variables. This is > following a database query. Right now they are in an array: > > $row[‘word_1’] > $row[‘word_2’] > $row[‘word_3’] > ... > $row[‘word_25’] Why those indices? Why isn't it just a numerically indexed array? > I am trying to use this while look to assign them to variables: > $word_1 > $word_2 > $word_3 > ... > $word_25 The first question that comes to mind is why the heck you would want to do such a thing? >${'word_'.$i} = stripslashes( eval ("echo $row['word_$i']") ); Eww, nasty. Why the eval? Why not just stripslashes($row['word_'.$i])? Variable variables have their uses, but this seems to be one of those cases where you're trying to get the square peg through the triangular hole. Take a step back and give us some more context. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Variable Question
I am trying to assign variables from an array into variables. This is following a database query. Right now they are in an array: $row[‘word_1’] $row[‘word_2’] $row[‘word_3’] ... $row[‘word_25’] I am trying to use this while look to assign them to variables: $word_1 $word_2 $word_3 ... $word_25 This is the WHILE loop: $i = 1; while ( $i <= 25 ) { ${'word_'.$i} = stripslashes( eval ("echo $row['word_$i']") ); ++$i; } What is confusing me is I don’t know how to represent the array variable. The specific error message I am receiving is: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING Can anyone see what I have done wrong and help me correct it? Thank you. Ron Ron Piggott www.TheVerseOfTheDay.info
RE: [PHP] Variable question
> -Original Message- > From: Ron Piggott [mailto:ron@actsministries.org] > Sent: 01 October 2011 18:59 > To: php-general@lists.php.net > Subject: [PHP] Variable question > > > If $correct_answer has a value of 3 what is the correct syntax > needed to use echo to display the value of $trivia_answer_3? > > I know this is incorrect, but along the lines of what I am wanting > to do: > > echo $trivia_answer_$correct_answer; Just for the record, one more way of doing what you asked for is: echo ${"trivia_answer_$correct_answer"}; But I totally agree with all the suggestions to use an array instead. Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Portland PD507, City Campus, Leeds Metropolitan University, Portland Way, LEEDS, LS1 3HE, United Kingdom E: m.f...@leedsmet.ac.uk T: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
Re: [PHP] Variable question
On Sat, 1 Oct 2011, Mike Mackintosh wrote: Best bet would to toss this into either an object or array for simplification, otherwise that type of syntax would need the use of eval. example: eval('echo $trivia_answer_'.$correct_answer.';'); You could do: $var = "trivia_answer_.$correct_answer"; echo $$var; But I agree that an array would be simpler. best bet would be to.. $trivia_answer = array(); $trivia_answer[1] = 1000; $trivia_answer[2] = 1250; $trivia_answer[3] = 2500; $trivia_answer[4] = 5000; echo $trivia_answer[$correct_answer]; You can define this a bit more simply: $trivia_answer = array ( 1 => 1000, 2 => 1250, 3 => 2500, 4 => 5000 ); You can do it even more simply by just giving the values, but indexes wil start at 0: Array ( [0] => 1000 [1] => 1250 [2] => 2500 [3] => 5000 ) While manually defining an array like this is only slightly less tedius than using 4 numbered variables, it's a lot easier to do if you're getting data from somewhere else (e.g. a database of trivia questions). To use the original way proposed, you'd have to keep constructing variable names, which arrays avoid quite nicely. In my opinion, the only real usefulness for a syntax like $$var (above) is if you want to do something with a bunch of variables in one go. For example: foreach (array ("title", "artist", "album", "label") as $field) echo ucwords($field) . ': ' . $$field . ''; The above comes from a function which manages only a single record, so no real need to use an array. I could of course, e.g. record['title'] etc, but I don't see much could be gained unless I needed to be able to manage an entire record as a single unit. Geoff. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable question
On 01 Oct 2011 at 18:59, Ron Piggott wrote: > If $correct_answer has a value of 3 what is the correct syntax needed to use > echo to display the value of $trivia_answer_3? > > I know this is incorrect, but along the lines of what I am wanting to do: > > echo $trivia_answer_$correct_answer; > > $trivia_answer_1 = “1,000”; > $trivia_answer_2 = “1,250”; > $trivia_answer_3 = “2,500”; > $trivia_answer_4 = “5,000”; Not completely obvious to me what you're trying to do but I assume its: echo '\$trivia_answer_' . $correct_answer . " = \"" . $somevalue . "\";"; -- Cheers -- Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable question
On 11-10-01 02:03 PM, Mike Mackintosh wrote: On Oct 1, 2011, at 1:59 PM, Ron Piggott wrote: If $correct_answer has a value of 3 what is the correct syntax needed to use echo to display the value of $trivia_answer_3? I know this is incorrect, but along the lines of what I am wanting to do: echo $trivia_answer_$correct_answer; $trivia_answer_1 = “1,000”; $trivia_answer_2 = “1,250”; $trivia_answer_3 = “2,500”; $trivia_answer_4 = “5,000”; Ron www.TheVerseOfTheDay.info Best bet would to toss this into either an object or array for simplification, otherwise that type of syntax would need the use of eval. example: eval('echo $trivia_answer_'.$correct_answer.';'); best bet would be to.. $trivia_answer = array(); $trivia_answer[1] = 1000; $trivia_answer[2] = 1250; $trivia_answer[3] = 2500; $trivia_answer[4] = 5000; echo $trivia_answer[$correct_answer]; Agreed the OP's value list isn't optimal, but eval is not needed to address the solution: Cheers, Rob. -- E-Mail Disclaimer: Information contained in this message and any attached documents is considered confidential and legally protected. This message is intended solely for the addressee(s). Disclosure, copying, and distribution are prohibited unless authorized. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable question
On Sat, Oct 1, 2011 at 10:59 AM, Ron Piggott wrote: > If $correct_answer has a value of 3 what is the correct syntax needed to > use echo to display the value of $trivia_answer_3? You can use variable variables [1] to access the variable by building its name in a string: $name = 'trivia_answer_' . $correct_answer; echo $$name; Peace, David [1] http://php.net/manual/en/language.variables.variable.php
Re: [PHP] Variable question
On Oct 1, 2011, at 1:59 PM, Ron Piggott wrote: > > If $correct_answer has a value of 3 what is the correct syntax needed to use > echo to display the value of $trivia_answer_3? > > I know this is incorrect, but along the lines of what I am wanting to do: > > echo $trivia_answer_$correct_answer; > > $trivia_answer_1 = “1,000”; > $trivia_answer_2 = “1,250”; > $trivia_answer_3 = “2,500”; > $trivia_answer_4 = “5,000”; > > Ron > > > > > www.TheVerseOfTheDay.info Best bet would to toss this into either an object or array for simplification, otherwise that type of syntax would need the use of eval. example: eval('echo $trivia_answer_'.$correct_answer.';'); best bet would be to.. $trivia_answer = array(); $trivia_answer[1] = 1000; $trivia_answer[2] = 1250; $trivia_answer[3] = 2500; $trivia_answer[4] = 5000; echo $trivia_answer[$correct_answer]; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Variable question
If $correct_answer has a value of 3 what is the correct syntax needed to use echo to display the value of $trivia_answer_3? I know this is incorrect, but along the lines of what I am wanting to do: echo $trivia_answer_$correct_answer; $trivia_answer_1 = “1,000”; $trivia_answer_2 = “1,250”; $trivia_answer_3 = “2,500”; $trivia_answer_4 = “5,000”; Ron www.TheVerseOfTheDay.info
Re: [PHP] variable question
How about: eval( '$lie' . x ) ; >>is there a way to use one variable to create another? >>Example >>$poo=1 >>and i want >>$lie1 >>OR >>$poo=2 >>and i want >>$lie2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variable question
Thanks oh so much "Robin Vickery" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Sat, 19 Jun 2004 14:25:27 -0600, water_foul > <[EMAIL PROTECTED]> wrote: > > > > is there a way to use one variable to create another? > > Example > > $poo=1 > > and i want > > $lie1 > > OR > > $poo=2 > > and i want > > $lie2 > > If I understand you right, you want: > > ${'lie' . $poo} > > when $poo is 1, that will give you $lie1, and when $poo is 2, it'll > give you $lie2. > > You're almost certain to be better off using arrays though,,, > > -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variable question
On Sat, 19 Jun 2004 14:25:27 -0600, water_foul <[EMAIL PROTECTED]> wrote: > > is there a way to use one variable to create another? > Example > $poo=1 > and i want > $lie1 > OR > $poo=2 > and i want > $lie2 If I understand you right, you want: ${'lie' . $poo} when $poo is 1, that will give you $lie1, and when $poo is 2, it'll give you $lie2. You're almost certain to be better off using arrays though,,, -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] variable question
is there a way to use one variable to create another? Example $poo=1 and i want $lie1 OR $poo=2 and i want $lie2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] variable question...
> -Original Message- > From: Justin Blake [mailto:[EMAIL PROTECTED]] > Sent: 16 April 2002 09:43 > > You can use variable variable names by adding another '$'. > so if $i == 1 and $var1 == "one", you can do this: > > $var_name = "var".$i; > if($$var_name == "one") echo "Hello!"; > > That should work, So should: if (${"var".$i} == "one) echo "Hello!"; Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variable question...
"Phil Schwarzmann" <[EMAIL PROTECTED]> wrote: > Let's say I a variable called $var1 and it's values is "one" > > ...I want to access them by doing something like this... > > $i = 1; > if ("var".$i == "one") echo "Hello!"; > > ...I want the combination of "var" and $i to equal $var1 > > How do I do this?? > The code I just wrote will not print out "Hello!" You can use variable variable names by adding another '$'. so if $i == 1 and $var1 == "one", you can do this: $var_name = "var".$i; if($$var_name == "one") echo "Hello!"; That should work, Justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] variable question...
Let's say I a variable called $var1 and it's values is "one" ...I want to access them by doing something like this... $i = 1; if ("var".$i == "one") echo "Hello!"; ...I want the combination of "var" and $i to equal $var1 How do I do this?? The code I just wrote will not print out "Hello!" THANKS!!! Phil
Re: [PHP] variable question
store $name on one line and $welcomemssg on a separate line. Then just remember that all odd numbered liens are names and even numbered lines are messages. =C= * * Cal Evans * Techno-Mage * http://www.calevans.com * - Original Message - From: "Jule Slootbeek" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, April 15, 2002 1:30 PM Subject: Re: [PHP] variable question > > Here's my code, teh $welcomemssg is one of the two variable store in > index.php the other one is $name > > $File = "welcome/index.php"; > $Open = fopen ($File, "r"); > if ($Open) { > print ("$welcomemssg"); > } > fclose ($Open); > ?> > > Jule > > On Monday 15 April 2002 13:49, you typed on your keyboard, and you sent me > the following: > On Tuesday 16 April 2002 00:41, Jule Slootbeek wrote: > > Hey Guys and Gals, > > I'm writing this little script that takes two inputs: $name and > > $welcomemssg from a form and puts them in a text file. Now i only want to > > extract one of those variables open it with welcome.php, how do i go > > about this? when i just do fopen and fwrite it prints both variables. > > any thoughts? > > Show us your code. > > -- > Jule Slootbeek > [EMAIL PROTECTED] > http://blindtheory.cjb.net > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variable question
Here's my code, teh $welcomemssg is one of the two variable store in index.php the other one is $name Jule On Monday 15 April 2002 13:49, you typed on your keyboard, and you sent me the following: On Tuesday 16 April 2002 00:41, Jule Slootbeek wrote: > Hey Guys and Gals, > I'm writing this little script that takes two inputs: $name and > $welcomemssg from a form and puts them in a text file. Now i only want to > extract one of those variables open it with welcome.php, how do i go > about this? when i just do fopen and fwrite it prints both variables. > any thoughts? Show us your code. -- Jule Slootbeek [EMAIL PROTECTED] http://blindtheory.cjb.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] variable question
You would need to read in the line and explode the line into an array using explode(). How you do this depends on how you wrote the variables to a file. If you separated them using a "," you could use $values = explode(",", $inputstring); see also: http://www.php.net/manual/en/function.explode.php David McInnis -Original Message- From: Jason Wong [mailto:[EMAIL PROTECTED]] Sent: Monday, April 15, 2002 10:49 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] variable question On Tuesday 16 April 2002 00:41, Jule Slootbeek wrote: > Hey Guys and Gals, > I'm writing this little script that takes two inputs: $name and > $welcomemssg from a form and puts them in a text file. Now i only want to > extract one of those variables open it with welcome.php, how do i go about > this? when i just do fopen and fwrite it prints both variables. > any thoughts? Show us your code. -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* Kissing your hand may make you feel very good, but a diamond and sapphire bracelet lasts for ever. -- Anita Loos, "Gentlemen Prefer Blondes" */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variable question
On Tuesday 16 April 2002 00:41, Jule Slootbeek wrote: > Hey Guys and Gals, > I'm writing this little script that takes two inputs: $name and > $welcomemssg from a form and puts them in a text file. Now i only want to > extract one of those variables open it with welcome.php, how do i go about > this? when i just do fopen and fwrite it prints both variables. > any thoughts? Show us your code. -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* Kissing your hand may make you feel very good, but a diamond and sapphire bracelet lasts for ever. -- Anita Loos, "Gentlemen Prefer Blondes" */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] variable question
Hey Guys and Gals, I'm writing this little script that takes two inputs: $name and $welcomemssg from a form and puts them in a text file. Now i only want to extract one of those variables open it with welcome.php, how do i go about this? when i just do fopen and fwrite it prints both variables. any thoughts? thanks, Jule -- Jule Slootbeek [EMAIL PROTECTED] http://blindtheory.cjb.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable question, yet another
put the array indices in single quote like : echo "[a href=\"myscript.php?username={$userdata['username']}\"]Goto MyScript.php[/a]"; - Original Message - From: "Jason Stechschulte" <[EMAIL PROTECTED]> To: "King, Justin" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: 2001. május 8. 21:22 Subject: Re: [PHP] Variable question, yet another > On Tue, May 08, 2001 at 01:20:49PM -0500, King, Justin wrote: > > So when the line hits type 1, it evals like this > > > > echo "[a href="myscript.php?username={$userdata["username"]}"]Goto > > MyScript.php[/a]"; > > > > Of course this yields an error because of the "'s in the anchor tag. > > But if I add slashes the evaluated code will be > > > > echo "[a href=\"myscript.php?username={$userdata[\"username\"]}\"]Goto > > MyScript.php[/a]"; > > Why not just break out of the string to print the username? > echo "[a href=\"myscript.php?username=".$userdata["username"]."\"]Goto > Myscript.php[/a]"; > > -- > Jason Stechschulte > [EMAIL PROTECTED] > -- > The whole history of computers is rampant with cheerleading at best and > bigotry at worst. > -- Larry Wall in <[EMAIL PROTECTED]> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Variable question, yet another
On Tue, May 08, 2001 at 01:20:49PM -0500, King, Justin wrote: > So when the line hits type 1, it evals like this > > echo "[a href="myscript.php?username={$userdata["username"]}"]Goto > MyScript.php[/a]"; > > Of course this yields an error because of the "'s in the anchor tag. > But if I add slashes the evaluated code will be > > echo "[a href=\"myscript.php?username={$userdata[\"username\"]}\"]Goto > MyScript.php[/a]"; Why not just break out of the string to print the username? echo "[a href=\"myscript.php?username=".$userdata["username"]."\"]Goto Myscript.php[/a]"; -- Jason Stechschulte [EMAIL PROTECTED] -- The whole history of computers is rampant with cheerleading at best and bigotry at worst. -- Larry Wall in <[EMAIL PROTECTED]> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Variable question, yet another
Alright... here's my situation for those that didn't read my string of messages yesterday.. (plus a bit more background information as to why I'm doing this) I'm writing an engine for a content managing system. Part of the system is a menu builder. I use 2 tables, (this is a mysql database) menu and menu_parts. They look like this Table menu ID : Integer; (auto increments, key) Name : Varchar[128]; Type : Integer; (unused now) Table menu_parts ID : Integer; Menu : Integer; (which menu this belongs to) Order : Tinyint; (all menu items have incremental numbers) Type : Tinyint; Data : Text; My code looks like this [code] $query="SELECT type,data FROM menu_parts WHERE menu='1' ORDER BY m_order"; $result=mysql_query($query); if($myrow=mysql_fetch_array($result)) { do { if($myrow["type"]==1) eval("echo \"".$myrow["data"]."\";"); elseif($myrow["type"]==2) eval($myrow["data"]); else echo $myrow["data"]; } while($myrow=mysql_fetch_array($result)); } [/code] So depending on the menu_parts type, it will display the data field differently. If the type=0, it simple outputs the data field plain text. If the type=1, it adds echo to both sides and outputs data. If the type=2, it evaluates the code as is. The problem I'm having, is with type 1. The main reason for this type is say I want to send the user to a php script and pass parameters (I'm going to use []'s so those of you with html email readers don't parse it) [a href="myscript.php?username={$userdata["username"]}"]Goto MyScript.php[/a] So when the line hits type 1, it evals like this echo "[a href="myscript.php?username={$userdata["username"]}"]Goto MyScript.php[/a]"; Of course this yields an error because of the "'s in the anchor tag. But if I add slashes the evaluated code will be echo "[a href=\"myscript.php?username={$userdata[\"username\"]}\"]Goto MyScript.php[/a]"; Which will cause the $userdata["username"] variable to not process properly. I thought about making type one do echo ''; instead of echo ""; but then if the user has a ' in their menu it won't function properly. I wish I could do this with regular expressions, but I'm not fluent with them (and also doubt I could succeed in my task if I did). I think I described my problem as thorough as I could have. Any help, comments, etc would be greatly appreciated. -Justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable question
this also works, since you mentioned that you're trying to get away from evalling an "echo" statement. $bob = "Roy"; $s = 'Hey there $bob'; $s = '$somevar = "'. $s .'";'; eval ($s); print $somevar; prints: "Hey there Roy"; personally, i think that using regexps to implement an entire symbol parsing engine to do what you ask is something that you really do not need to do. instead of trying to reinvent the wheel, use the free ferarri that PHP provides you :) > -Original Message- > From: King, Justin [mailto:[EMAIL PROTECTED]] > Sent: Monday, May 07, 2001 4:29 PM > To: [EMAIL PROTECTED] > Subject: RE: [PHP] Variable question > > > I'm trying to get around having to do that, I don't know regular > expressions so it makes it difficult :( > > -Justin > > -Original Message- > From: "John Vanderbeck" <[EMAIL PROTECTED]> > Sent: Monday, May 07, 2001 1:21 PM > To: King, Justin; [EMAIL PROTECTED] > Subject: RE: [PHP] Variable question > > How about manually parsing the string out to give you chunks, that can > then > be eval'd easy. > > - John Vanderbeck > - Admin, GameDesign (http://gamedesign.incagold.com/) > - GameDesign, the industry source for game design and development issues > > > > -Original Message- > > From: King, Justin [mailto:[EMAIL PROTECTED]] > > Sent: Monday, May 07, 2001 4:18 PM > > To: [EMAIL PROTECTED] > > Subject: RE: [PHP] Variable question > > > > > > A simple eval($mysqldata) isn't going to do it though since the string > > is "Your username is $userdata["username"]"; it'll just spit a parse > > error. I've already tried that > > > > -Justin > > > > -Original Message- > > From: "Jack Dempsey" <[EMAIL PROTECTED]> > > Sent: Monday, May 07, 2001 1:13 PM > > To: King, Justin; [EMAIL PROTECTED] > > Subject: RE: [PHP] Variable question > > > > ok, look into eval() > > > > -Original Message- > > From: King, Justin [mailto:[EMAIL PROTECTED]] > > Sent: Monday, May 07, 2001 4:07 PM > > To: [EMAIL PROTECTED] > > Subject: RE: [PHP] Variable question > > > > > > Here let me flesh this out a bit more > > > > Consider the query "SELECT datafield FROM myTable WHERE id=1"; > > > > This would return "My username is $userdata["username"]"; > > > > I want to then output what the database returns, and have php evaluate > > my variables. > > > > -Justin > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: > [EMAIL PROTECTED] > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: > [EMAIL PROTECTED] > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: > [EMAIL PROTECTED] > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable question (eval is cool)
$bob = "Roy"; $s = 'Hey there $bob'; $s = 'print "'. $s .'";'; eval ($s); prints: "Hey there Roy"; perhaps that's what you're looking for? > -Original Message- > From: John Vanderbeck [mailto:[EMAIL PROTECTED]] > Sent: Monday, May 07, 2001 4:21 PM > To: King, Justin; [EMAIL PROTECTED] > Subject: RE: [PHP] Variable question > > > How about manually parsing the string out to give you chunks, that can then > be eval'd easy. > > - John Vanderbeck > - Admin, GameDesign (http://gamedesign.incagold.com/) > - GameDesign, the industry source for game design and development issues > > > > -Original Message- > > From: King, Justin [mailto:[EMAIL PROTECTED]] > > Sent: Monday, May 07, 2001 4:18 PM > > To: [EMAIL PROTECTED] > > Subject: RE: [PHP] Variable question > > > > > > A simple eval($mysqldata) isn't going to do it though since the string > > is "Your username is $userdata["username"]"; it'll just spit a parse > > error. I've already tried that > > > > -Justin > > > > -Original Message- > > From: "Jack Dempsey" <[EMAIL PROTECTED]> > > Sent: Monday, May 07, 2001 1:13 PM > > To: King, Justin; [EMAIL PROTECTED] > > Subject: RE: [PHP] Variable question > > > > ok, look into eval() > > > > -Original Message- > > From: King, Justin [mailto:[EMAIL PROTECTED]] > > Sent: Monday, May 07, 2001 4:07 PM > > To: [EMAIL PROTECTED] > > Subject: RE: [PHP] Variable question > > > > > > Here let me flesh this out a bit more > > > > Consider the query "SELECT datafield FROM myTable WHERE id=1"; > > > > This would return "My username is $userdata["username"]"; > > > > I want to then output what the database returns, and have php evaluate > > my variables. > > > > -Justin > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable question
I'm trying to get around having to do that, I don't know regular expressions so it makes it difficult :( -Justin -Original Message- From: "John Vanderbeck" <[EMAIL PROTECTED]> Sent: Monday, May 07, 2001 1:21 PM To: King, Justin; [EMAIL PROTECTED] Subject: RE: [PHP] Variable question How about manually parsing the string out to give you chunks, that can then be eval'd easy. - John Vanderbeck - Admin, GameDesign (http://gamedesign.incagold.com/) - GameDesign, the industry source for game design and development issues > -Original Message- > From: King, Justin [mailto:[EMAIL PROTECTED]] > Sent: Monday, May 07, 2001 4:18 PM > To: [EMAIL PROTECTED] > Subject: RE: [PHP] Variable question > > > A simple eval($mysqldata) isn't going to do it though since the string > is "Your username is $userdata["username"]"; it'll just spit a parse > error. I've already tried that > > -Justin > > -Original Message- > From: "Jack Dempsey" <[EMAIL PROTECTED]> > Sent: Monday, May 07, 2001 1:13 PM > To: King, Justin; [EMAIL PROTECTED] > Subject: RE: [PHP] Variable question > > ok, look into eval() > > -Original Message- > From: King, Justin [mailto:[EMAIL PROTECTED]] > Sent: Monday, May 07, 2001 4:07 PM > To: [EMAIL PROTECTED] > Subject: RE: [PHP] Variable question > > > Here let me flesh this out a bit more > > Consider the query "SELECT datafield FROM myTable WHERE id=1"; > > This would return "My username is $userdata["username"]"; > > I want to then output what the database returns, and have php evaluate > my variables. > > -Justin > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable question
I understand that, but that's what I'm trying to get around doing. -Justin -Original Message- From: CC Zona <[EMAIL PROTECTED]> Sent: Monday, May 07, 2001 1:24 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Variable question In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] ("King, Justin") wrote: > A simple eval($mysqldata) isn't going to do it though since the string > is "Your username is $userdata["username"]"; it'll just spit a parse > error. I've already tried that The code being eval'd has to be a valid PHP statement. So if you want to echo that string, then "echo" must be part of the eval'd code. Terminated with semi-colon, etc. eval("echo 'Your username is ' . $userdata['username'];"); -- CC -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Variable question
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] ("King, Justin") wrote: > A simple eval($mysqldata) isn't going to do it though since the string > is "Your username is $userdata["username"]"; it'll just spit a parse > error. I've already tried that The code being eval'd has to be a valid PHP statement. So if you want to echo that string, then "echo" must be part of the eval'd code. Terminated with semi-colon, etc. eval("echo 'Your username is ' . $userdata['username'];"); -- CC -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable question
How about manually parsing the string out to give you chunks, that can then be eval'd easy. - John Vanderbeck - Admin, GameDesign (http://gamedesign.incagold.com/) - GameDesign, the industry source for game design and development issues > -Original Message- > From: King, Justin [mailto:[EMAIL PROTECTED]] > Sent: Monday, May 07, 2001 4:18 PM > To: [EMAIL PROTECTED] > Subject: RE: [PHP] Variable question > > > A simple eval($mysqldata) isn't going to do it though since the string > is "Your username is $userdata["username"]"; it'll just spit a parse > error. I've already tried that > > -Justin > > -Original Message- > From: "Jack Dempsey" <[EMAIL PROTECTED]> > Sent: Monday, May 07, 2001 1:13 PM > To: King, Justin; [EMAIL PROTECTED] > Subject: RE: [PHP] Variable question > > ok, look into eval() > > -Original Message- > From: King, Justin [mailto:[EMAIL PROTECTED]] > Sent: Monday, May 07, 2001 4:07 PM > To: [EMAIL PROTECTED] > Subject: RE: [PHP] Variable question > > > Here let me flesh this out a bit more > > Consider the query "SELECT datafield FROM myTable WHERE id=1"; > > This would return "My username is $userdata["username"]"; > > I want to then output what the database returns, and have php evaluate > my variables. > > -Justin > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable question
A simple eval($mysqldata) isn't going to do it though since the string is "Your username is $userdata["username"]"; it'll just spit a parse error. I've already tried that -Justin -Original Message- From: "Jack Dempsey" <[EMAIL PROTECTED]> Sent: Monday, May 07, 2001 1:13 PM To: King, Justin; [EMAIL PROTECTED] Subject: RE: [PHP] Variable question ok, look into eval() -Original Message- From: King, Justin [mailto:[EMAIL PROTECTED]] Sent: Monday, May 07, 2001 4:07 PM To: [EMAIL PROTECTED] Subject: RE: [PHP] Variable question Here let me flesh this out a bit more Consider the query "SELECT datafield FROM myTable WHERE id=1"; This would return "My username is $userdata["username"]"; I want to then output what the database returns, and have php evaluate my variables. -Justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable question
ok, look into eval() -Original Message- From: King, Justin [mailto:[EMAIL PROTECTED]] Sent: Monday, May 07, 2001 4:07 PM To: [EMAIL PROTECTED] Subject: RE: [PHP] Variable question Here let me flesh this out a bit more Consider the query "SELECT datafield FROM myTable WHERE id=1"; This would return "My username is $userdata["username"]"; I want to then output what the database returns, and have php evaluate my variables. -Justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable question
Here let me flesh this out a bit more Consider the query "SELECT datafield FROM myTable WHERE id=1"; This would return "My username is $userdata["username"]"; I want to then output what the database returns, and have php evaluate my variables. -Justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable question
I'm not sure what you mean... [code] $query = "SELECT username FROM Users WHERE userid=1"; $result = mysql_query($query, $link); $user_data = mysql_fetch_assoc($result); echo "my user name is ".$user_data["username"]; [/code] Is that _not_ what you mean? - John Vanderbeck - Admin, GameDesign (http://gamedesign.incagold.com/) - GameDesign, the industry source for game design and development issues > -Original Message- > From: King, Justin [mailto:[EMAIL PROTECTED]] > Sent: Monday, May 07, 2001 3:58 PM > To: [EMAIL PROTECTED] > Subject: RE: [PHP] Variable question > > > I think you're misunderstanding my question. I'm pulling > $user_data["username"] from a databse so the string my user name is > $user_data["username"]" is exactly as the database hands it to me. I > know how to simply concat information. > > -Justin > > -Original Message- > From: "Jack Dempsey" <[EMAIL PROTECTED]> > Sent: Monday, May 07, 2001 12:55 PM > To: King, Justin; [EMAIL PROTECTED] > Subject: RE: [PHP] Variable question > > you can do it a couple ways... > > echo "my user name is " . $user_data["username"]; > > or > > echo "my username is ${user_data["username"]}"; > > -Original Message- > From: King, Justin [mailto:[EMAIL PROTECTED]] > Sent: Monday, May 07, 2001 3:49 PM > To: [EMAIL PROTECTED] > Subject: [PHP] Variable question > > > How can I evaluate a variable in a string? For example if I have a > string defined as "my user name is $user_data["username"]", how do I > echo that string and have php evaluate $user_data["username"]. > > Thanks in advance.. > > -Justin > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable question
I think you're misunderstanding my question. I'm pulling $user_data["username"] from a databse so the string my user name is $user_data["username"]" is exactly as the database hands it to me. I know how to simply concat information. -Justin -Original Message- From: "Jack Dempsey" <[EMAIL PROTECTED]> Sent: Monday, May 07, 2001 12:55 PM To: King, Justin; [EMAIL PROTECTED] Subject: RE: [PHP] Variable question you can do it a couple ways... echo "my user name is " . $user_data["username"]; or echo "my username is ${user_data["username"]}"; -Original Message- From: King, Justin [mailto:[EMAIL PROTECTED]] Sent: Monday, May 07, 2001 3:49 PM To: [EMAIL PROTECTED] Subject: [PHP] Variable question How can I evaluate a variable in a string? For example if I have a string defined as "my user name is $user_data["username"]", how do I echo that string and have php evaluate $user_data["username"]. Thanks in advance.. -Justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Variable question
Try this one : $user_data['username'] = 'Alphonse'; $str = "my user name is {$user_data['username']}"; Papp Gyozo - [EMAIL PROTECTED] - Original Message - From: "King, Justin" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: 2001. május 7. 21:48 Subject: [PHP] Variable question How can I evaluate a variable in a string? For example if I have a string defined as "my user name is $user_data["username"]", how do I echo that string and have php evaluate $user_data["username"]. Thanks in advance.. -Justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Variable question
you can do it a couple ways... echo "my user name is " . $user_data["username"]; or echo "my username is ${user_data["username"]}"; -Original Message- From: King, Justin [mailto:[EMAIL PROTECTED]] Sent: Monday, May 07, 2001 3:49 PM To: [EMAIL PROTECTED] Subject: [PHP] Variable question How can I evaluate a variable in a string? For example if I have a string defined as "my user name is $user_data["username"]", how do I echo that string and have php evaluate $user_data["username"]. Thanks in advance.. -Justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Variable question
How can I evaluate a variable in a string? For example if I have a string defined as "my user name is $user_data["username"]", how do I echo that string and have php evaluate $user_data["username"]. Thanks in advance.. -Justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] variable question
thats right you could do that, but it sucks. (IMHO) $test->s0 $test->s1 $test->s2 for($c = 0; $c < 3; $c++) { $name = "s$c"; echo $test->$name; } but this is better, more modular. $test->s[0] $test->s[1] $test->s[2] foreach($test->s as $pos => $val) echo $val; with the second example you can add another element to $test->s and the loop will auto adjust for this. but both methods work. Chris Lee Mediawaveonline.com Joe Stump <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Put them in an array? PHP allows for variable variables, but I'm not sure they > work with classes. > > This works: > > $foo0 = 'a'; > $foo1 = 'b'; > $foo2 = 'c'; > $foo3 = 'd'; > $foo4 = 'e'; > > for($i = 0 ; $i < 5 ; ++$i) > { >$var = 'foo'.$i; >echo $$var; > } > > Try it with an object... > > --Joe > > > On Fri, Jan 19, 2001 at 05:15:25PM -0500, Michael Zornek wrote: > > ok so i have an object that has (among other things) the following properties: > > > > $vendor_data->s9 > > $vendor_data->s10 > > $vendor_data->s11 > > $vendor_data->s12 > > ... > > $vendor_data->s40 > > > > The values are 1 or 0 > > > > I'd like to write a loop to say: > > > > for ($count=9; $count>40; $count++) { > > if ($vendor_data->s(insert_number_here) == 1) { > > echo something; > > } > > } > > > > any thoughts? > > > > Mike > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- > > Joe Stump, PHP Hacker > [EMAIL PROTECTED] > http://www.miester.org/ > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] variable question
Put them in an array? PHP allows for variable variables, but I'm not sure they work with classes. This works: $foo0 = 'a'; $foo1 = 'b'; $foo2 = 'c'; $foo3 = 'd'; $foo4 = 'e'; for($i = 0 ; $i < 5 ; ++$i) { $var = 'foo'.$i; echo $$var; } Try it with an object... --Joe On Fri, Jan 19, 2001 at 05:15:25PM -0500, Michael Zornek wrote: > ok so i have an object that has (among other things) the following properties: > > $vendor_data->s9 > $vendor_data->s10 > $vendor_data->s11 > $vendor_data->s12 > ... > $vendor_data->s40 > > The values are 1 or 0 > > I'd like to write a loop to say: > > for ($count=9; $count>40; $count++) { > if ($vendor_data->s(insert_number_here) == 1) { > echo something; > } > } > > any thoughts? > > Mike > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- Joe Stump, PHP Hacker [EMAIL PROTECTED] http://www.miester.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] variable question
ok so i have an object that has (among other things) the following properties: $vendor_data->s9 $vendor_data->s10 $vendor_data->s11 $vendor_data->s12 ... $vendor_data->s40 The values are 1 or 0 I'd like to write a loop to say: for ($count=9; $count>40; $count++) { if ($vendor_data->s(insert_number_here) == 1) { echo something; } } any thoughts? Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]