0

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

1 Answer 1

2

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 );
}
Sign up to request clarification or add additional context in comments.

1 Comment

i think you did not understand my question, instead call them in order, i would like to call them as following getMyValue("OrderLineItemID",$Type3) or getMyValue("Name",$Type3) or getMyValue("Something-else",$Type3) and the parameter $Type3 is depending on ebayOrder, which is depending on Type2 etc ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.