-1

Hi after this lines of codes:
$client = new SoapClient("http://rscnagahrd/OracleWS/Oracle.asmx?WSDL");
$result = $client->getFoods();
$objResult = simplexml_load_string($result->getFoodsResult->any);

I want to extract the values from $objResult's Tags to a PHP Variable.

When I var_dump($objResult);

I get:

object(SimpleXMLElement)#4 (1) { 
["NewDataSet"]=> object(SimpleXMLElement)#5 (1) { 
    ["Table"]=> array(4) { 
        [0]=> object(SimpleXMLElement)#6 (4) { 
            ["FOOD_ID"]=> string(1) "1" 
            ["FOOD_NAME"]=> string(6) "Burger" 
            ["FOOD_DESC"]=> string(15) "100% Beef Patty" 
            ["FOOD_PRICE"]=> string(2) "25" 
        } 
        [1]=> object(SimpleXMLElement)#7 (4) { 
            ["FOOD_ID"]=> string(1) "2" 
            ["FOOD_NAME"]=> string(4) "Coke" 
            ["FOOD_DESC"]=> string(6) "Drinks" 
            ["FOOD_PRICE"]=> string(2) "10" 
        } 
        [2]=> object(SimpleXMLElement)#8 (4) { 
            ["FOOD_ID"]=> string(1) "3" 
            ["FOOD_NAME"]=> string(5) "Pepsi" 
            ["FOOD_DESC"]=> string(6) "Drinks" 
            ["FOOD_PRICE"]=> string(2) "10" 
        } 
        [3]=> object(SimpleXMLElement)#9 (4) { 
            ["FOOD_ID"]=> string(1) "4" 
            ["FOOD_NAME"]=> string(12) "French Fries" 
            ["FOOD_DESC"]=> string(16) "Made from France" 
            ["FOOD_PRICE"]=> string(2) "15" 
        } 
    } 
} 

}

I want to for example store all items with TAG "FOOD_NAME" be assigned to a PHP variable
$foodname(0)

1
  • This question appears to be off-topic because it is about asking the same that has been outlined in the PHP manual. See Basic SimpleXML usage Commented Jul 4, 2013 at 15:02

1 Answer 1

0

Try this:

$foodname = array();
foreach ($objResult->NewDataSet->Table as $table) {
    $foodname[] = $table->FOOD_NAME;
}

echo $foodname[0]; // first element of the array
Sign up to request clarification or add additional context in comments.

2 Comments

Hi, your solution worked but when I echo $foodname all the names are displayed, ie. BurgerCokePepsiFrench Fries, I tried $foodname[0] but it displays only B and $foodname[1] displays u..etc..
In that case use array , answer updated

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.