嗨,这行代码后:
$client = new SoapClient("http://rscnagahrd/OracleWS/Oracle.asmx?WSDL");
$result = $client->getFoods();
$objResult = simplexml_load_string($result->getFoodsResult->any);
我想将$objResult
的标签中的值提取为PHP变量。
I var_dump($objResult);
我明白了:
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"
}
}
}
}
我想例如将所有带有TAG“FOOD_NAME”的项目存储到PHP变量中
$foodname(0)
答案 0 :(得分:0)
试试这个:
$foodname = array();
foreach ($objResult->NewDataSet->Table as $table) {
$foodname[] = $table->FOOD_NAME;
}
echo $foodname[0]; // first element of the array