-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)

PaulPolon
  • 319
  • 1
  • 5
  • 17
  • 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](http://php.net/simplexml.examples-basic) – hakre Jul 04 '13 at 15:02

1 Answers1

0

Try this:

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

echo $foodname[0]; // first element of the array
Manoj Yadav
  • 6,560
  • 1
  • 23
  • 21
  • 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.. – PaulPolon Jul 04 '13 at 07:20
  • In that case use `array` , answer updated – Manoj Yadav Jul 04 '13 at 07:22