Jump to content

Is there anyway to do this?


l0ve2hat3

Recommended Posts

You can use variable variables. I'll let you look up in the manual how, because they are not the best way of using sets of related data.

 

Any time you have a set (two or more) of related data, use an array instead of sequentially named variables. Using variable variables are 3 times slower than an array and the code necessary to set create, keep track of how many of them there are, and access them is more complicated than if you just use an array.

You can't create a variable or use it's value in the manner in which you have tried to do. I recommend using an array:

 

<?php
$josh1[] = "it worked";
for($i=0;$i<=3;$i++){
     if(isset($jost1["$i"])){
          echo $josh1["$i"];
     }
}
?>

My first hand experience with variable variables was that I was in here a while back trying to use them and it was said that it couldn't be done...

 

Probably reading this will help - http://www.php.net/manual/en/language.variables.variable.php

 

Variable variables do exist. Please don't post information unless you have first hand knowledge of what you are posting.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.