Classes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • feldon23
    Senior Member
    • Nov 2001
    • 11291
    • 3.7.x

    Classes

    Forgive my complete ignorance of PHP classes.

    I am extending a piece of code that does this:

    Code:
    <?php echo $row->cust_1;?>
    <?php echo $row->cust_2;?>
    <?php echo $row->cust_3;?>
    Can I make a for() loop to change the 1 to a 2, 3, etc.?
  • Steve Machol
    Former Customer Support Manager
    • Jul 2000
    • 154488

    #2
    I can't help you with your question, but I can forgive you. Go in Peace, my son.
    Steve Machol, former vBulletin Customer Support Manager (and NOT retired!)
    Change CKEditor Colors to Match Style (for 4.1.4 and above)

    Steve Machol Photography


    Mankind is the only creature smart enough to know its own history, and dumb enough to ignore it.


    Comment

    • Chroder
      Senior Member
      • Dec 2002
      • 1449

      #3
      I think you can use variable variables.

      PHP Code:
      for($i 1$i <= 3$i++)
      {
          
      $var 'cust_' $i;
          echo 
      $row->$var;

      Or using eval:
      PHP Code:
      for($i 1$i <= 3$i++)
       {
           
      $var 'cust_' $i;
          eval(
      'echo $row->' $var ';');
       } 

      Comment

      widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
      Working...