Announcement

Collapse
No announcement yet.

help with variabales in variable names

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • krs-one
    replied
    What freddie said.

    Well, you could use an array for what you described. Just make it multidimensional.

    -Vic

    Leave a comment:


  • megahard
    replied
    thanx i used the top one and it worked perfectly.

    the reason i cant use an array is becoz the results are coming from a mysql db, and different amounts of rows will be present, i simplified it to make it easy to understand.

    seems to have worked

    thanx a lot!

    Leave a comment:


  • Freddie Bingham
    replied
    PHP Code:
    while($i AND ${answer.$i} != '') { 
    ;

    or:
    PHP Code:
    while ($i 4) {
      
    $temp "answer$i";
      if ($
    $temp != '') {
        ;
      }

    or probably a better strategy:
    PHP Code:
    $answer = array();
    $answer[] = 'something';
    $answer[] = 'something else';
    $answer[] = ' and yet';
    $answer[] = 'something else again';
    foreach (
    $answer as $index => $value) {
      echo 
    "index -- $value<br />";

    or:
    PHP Code:
    $answer = array('something''something else'' and yet''something else again');
    foreach (
    $answer as $index => $value) {
      echo 
    "index -- $value<br />";

    Leave a comment:


  • megahard
    replied
    nope, didnt work

    Leave a comment:


  • krs-one
    replied
    Something like:

    PHP Code:
    $var = eval("\$answer$i"); 
    Should work. Untested, and I am not 100% sure, but you should use the eval() function.

    Search for it on php.net

    -Vic

    Leave a comment:


  • megahard
    replied
    i think u miss understood

    using $i=0;
    im trying to tell it to get the varible $answer0;

    Leave a comment:


  • krs-one
    replied
    I am not 100% sure, but I think you can use the eval() function. It evaluates a string as PHP code and then interprets it.

    http://www.php.net/

    -Vic

    Leave a comment:


  • megahard
    started a topic help with variabales in variable names

    help with variabales in variable names

    say i have:

    $answer0
    $answer1
    $answer2
    $answer3

    then i wana say:

    $i=0;
    while($i<4 && ___$answer.$i___ !=""){
    ......;}

    ___$answer.$i___ needs changing to sumthing that works, how could i do this?
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...
X