943,169 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 16
  • PHP RSS
Sep 2nd, 2010
0

Syntax Question

Expand Post »
Good Afternoon,

I have this line of code:

echo $sum['PTS1011_wk1'];

Earlier in my page, I have set a variable to:

$wk="wk1";

What is the syntax to use the Variable $wk instead of spelling out wk1.

I want to be able to change $wk once and have it change throughout a number of pages.

Thanks
Chris
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
ceeandcee is offline Offline
72 posts
since Aug 2010
Sep 2nd, 2010
1
Re: Syntax Question
It's been a while since I worked with PHP, but I'm sure you can just put the variable directly in the braces.

echo $sum[$wk];

If you need the rest of the string that you have entered, change the single-quotes to double-quotes. PHP will resolve a variable that's contained within double-quotes.

echo $sum["PTS1011_$wk"];
Last edited by Fbody; Sep 2nd, 2010 at 7:31 pm.
Featured Poster
Reputation Points: 833
Solved Threads: 392
Posting Maven
Fbody is offline Offline
2,846 posts
since Oct 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: pagination
Next Thread in PHP Forum Timeline: sending variables from a form with an array





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC