lazy saunter

(personal learnings in computation)

Tuesday, September 25, 2007

"variable variables" in PHP

several times i've had the situation where an "include" file would contain variables with values that would be used throughout a site. the variable "$page5" contains the name of the fifth file to be viewed navigating sequentially through the site.

there is a variable that keeps the number of the first page that has not been viewed. if the user has viewed the first four pages (let's call it $_SESSION['next_to_view']), this variable would contain '5'.

to do this, you must create a regular variable:

$next = 'page' . $_SESSION['next_to_view'];

this stores the value 'page5' in '$next';

in order to get the value of '$page5', you must call '$$next'.

both simple and a little tricky to grasp, this is worth noting because it is easily forgotten.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home