user3380607
user3380607

Reputation: 1

variable in loop function

I want to get the value from a loop function but am stuck in this problem, maybe you guys can give me help, thanks.

I define the parameters here

$my_value1 = "Order";
$my_value2 = "Transaction";
$my_value3 = "Name";

$doc2 = new DOMDocument(); 
$doc2->load( 'GetOrders.xml' ); 
$info2 = $doc2->getElementsByTagName( $my_value1 );
foreach( $info2 as $Type2 )
{
    $ebayOrder = $Type2->getElementsByTagName($my_value2);
        foreach($ebayOrder as $Type3)
       {    

        echo getMyValue("OrderLineItemID",$Type3); echo '</br>';

       }

The problem is that I want to call something like set the my_value2 in the loop and call something like getMyValue($my_value3,$Type3)

Is possible to rewrite the function, so I can always call using the new parameter?

thanks in advance,

Mike

Upvotes: 0

Views: 62

Answers (1)

hsz
hsz

Reputation: 152216

You can use variables as a parts of the names of other variables. Try with:

for ($i = 1; $i <= 3; $i++) {
  $my_value = ${'my_value' . $i};
  $info2 = $doc2->getElementsByTagName( $my_value );
}

Upvotes: 2

Related Questions