Hello to you all..

This is my first post, so please be gentle.. 🙂

I am a little stuck, trying to populate input fields from and std object through an foreach.

What I am trying, is call the value of the std object, and a adding a dynamic value to the call.

Example:

<input id="example<?php echo $j; ?>" name="example<?php echo $j; ?>"  value="[B][COLOR="Red"]<?php echo $object[0]->cell.$j; ?>[/COLOR][/B]

The syntax i am trying to create:
echo $object[0]->cell1
echo $object[0]->cell2
echo $object[0]->cell3
etc...

But no matter what I try, I just can't get the right syntax..
Hope you can help me..
Best regards Allen..

    Can you show us the output of:

    <?php echo "<pre>".print_r($object,true)."</pre>";?>
    

    ?

      Hello NogDog,

      Thanks for your fast reply..

      This is an example of the object..

      Array
      (
          [0] => stdClass Object
              (
                  [id] => 5
                  [group_id] => 6
                  [cell1] => test 
                  [product1] => test
                  [productdec1] => test
                  [ref1] => test
                  [sku1] => test
                  [quantity1] => test 
                  [cell2] => test
                  [product2] => test
                  [productdec2] => test
                  [ref2] => test
                  [sku2] => test
                  [quantity2] => test
                  [cell3] => test
                  [product3] => test
                  [productdec3] => test
                  [ref3] => test
                  [sku3] => test
                  [quantity3] => test
                  [cell4] => test
                  [product4] => test
                  [productdec4] => test
                  [ref4] => test
                  [sku4] => test
                  [quantity4] => test 
      
          )
      
      )

      Allen.

        OK, now I think I understand. You can build the name in a variable, then use it for the desired object property:

        $name = 'cell' . $j;
        echo $object[0]->$name;
        

          PS: looks like you could do this, too:

          echo $object[0]->{"cell".$j};
          

            Fantastic..!! That did the trick..!!! 🙂

            Thank you so much.. Been struggling for hours with this..

              Write a Reply...