XMLを取得して配列を作成し、APIを介して更新できるようにするための次のコードがあります。
$data1 = file_get_contents('neworderexample.xml');
$xml = new SimpleXMLElement($data1,LIBXML_NOCDATA);
foreach($xml -> Product as $ord){
$sku = $ord -> StockNumber;
$title = $ord -> Title;
$retail_price = $ord -> RRP;
$price = $ord -> SellPrice;
$description = $ord -> Description;
$inventory_level = $ord -> StockLevel;
$weight = $ord -> Weight;
$width = $ord -> Width;
$prodheight = $ord -> Height;
$depth = $ord -> Depth;
$fields = array(
"sku" => $sku,
"name" => $title,
"retail_price" => $retail_price,
"price" => $price,
"description " => $description,
"inventory_level " => $inventory_level,
"type" => "physical",
"availability" => "available",
"weight" => $weight,
"width" => $width,
"prodheight" => $prodheight,
"depth" => $depth,
"categories" => "1"
);
print_r ($fields);
変数をエコーすると値だけが得られますが、配列を出力すると次のようになります。
[inventory_level ] => SimpleXMLElement Object ( [0] => 9 )
[type] => physical
[availability] => available
[weight] => SimpleXMLElement Object ( [@attributes] => Array ( [unit] => g ) [0] => 0.0 )
[width] => SimpleXMLElement Object ( [@attributes] => Array ( [unit] => (mm) ) [0] => 0 )
[prodheight] => SimpleXMLElement Object ( [@attributes] => Array ( [unit] => (mm) ) [0] => 0 )
[depth] => SimpleXMLElement Object ( [@attributes] => Array ( [unit] => (mm) ) [0] => 0 )
[categories] => 1 )
配列内の値のみを取得するにはどうすればよいですか?