dcole.ath.cx Posted June 19, 2006 Share Posted June 19, 2006 can I have a var in a var, then have it in a for statement that counts up..like have if I had:$group1person$group2person$group3person$group4personand instead have for ($i = 0, $i<5, $i++){($group($i)person) ...}...then use that $group($i)person for more PHP. I'm looking for a way so I don't have to write out each var. with a number. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 19, 2006 Share Posted June 19, 2006 for ($i = 0, $i<5, $i++){ $varname = "group{$i}person"; // now use $$varname $$varname = "this is group {$i}";} http://www.php.net/manual/en/language.variables.variable.php Link to comment Share on other sites More sharing options...
dcole.ath.cx Posted June 19, 2006 Author Share Posted June 19, 2006 this statement that I'm working on is getting to hard... I know have to put that within 5 inner going for and if statements that have aton of var. that need the same $ican I use $group{$i}personwell I'll be back tomorrow, maybe I'll use that first way... I'm going to need time to think about it... Link to comment Share on other sites More sharing options...
justsomeguy Posted June 19, 2006 Share Posted June 19, 2006 You can just make the name of the variable you want inside a string (without the first $), and then reference it as a variable variable like I showed above. $var = "hello";$$var = "test";//now $hello == "test" Link to comment Share on other sites More sharing options...
dcole.ath.cx Posted June 20, 2006 Author Share Posted June 20, 2006 I really wanted an easier way... I have now have to do something like that to the 3rd, 20 times.. GRRthanks for the help!I lost my Easy button, can I borrow some one's to find mine... Link to comment Share on other sites More sharing options...
justsomeguy Posted June 20, 2006 Share Posted June 20, 2006 I thought I answered your question, that is how you reference a variable with a name like "$group2person" or "$group3person" or some variable where you programmatically determine the name. What are you trying to do? Link to comment Share on other sites More sharing options...
SFB Posted June 20, 2006 Share Posted June 20, 2006 I bet he is working on his search engine. there is probably an easier way to do it but knowing dcole... one time he had to use 4 different types of quotes. Link to comment Share on other sites More sharing options...
dcole.ath.cx Posted June 20, 2006 Author Share Posted June 20, 2006 I still have that 4 quote thing, it's the advanced post.well I needed for something like:$group{$i}person$joe{$i}sun$bob{$i}mon...It did help a little bit, it condenced 100 lines of code into 20.There may have been an easier way but this way keeps my code looking alike. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 20, 2006 Share Posted June 20, 2006 I don't think there are 4 different types of quotes. There are single-quotes and double-quotes, what else? There aren't triple or quadruple quotes, and a backtick (`) isn't a quote at all. In fact, in PHP, a backtick does something substantially different then a quote.If you think you need 4 different types of quotes, you might want to re-think your design.. Link to comment Share on other sites More sharing options...
aspnetguy Posted June 20, 2006 Share Posted June 20, 2006 I still have that 4 quote thinghave you heard of escaping quotes $code = '<a href="javascript:myFunction(\'someParam\')">Click</a>'; Link to comment Share on other sites More sharing options...
dcole.ath.cx Posted June 20, 2006 Author Share Posted June 20, 2006 what aspnetguy said, I needed to use the \' and \" but it turns out I had to use them in the correct order... because if I didn't it got messed up, so that's why there was such a big deal abour 4 quotes. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 20, 2006 Share Posted June 20, 2006 Oh, I wouldn't consider an escaped quote another "type" of quote. A ' and a \' are the same, they are both single quotes, but one is escaped and one is not, it just depends where you use it.I can't for the life of me remember which project I'm thinking of, but I did have some pretty nasty-looking echo statements for something. I would echo some javascript code, inside of a quoted HTML attribute, where the javascript function call has quotes around the parameters, and the parameters themselves had escaped quotes. It was something like 8 slashes followed by a quote. Pretty ugly. Link to comment Share on other sites More sharing options...
dcole.ath.cx Posted June 20, 2006 Author Share Posted June 20, 2006 I lost my Easy button, can I borrow some one's to find mine...<{POST_SNAPBACK}> so... nobody is going to help me find my easy button? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 20, 2006 Share Posted June 20, 2006 There's no such thing as an Easy button. There is an Elegant button, and a Speed button, and definately a Bloated Unreadable Crap button, but not so much Easy. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now