Home > Backend Development > PHP Tutorial > 有关取一个obj的值

有关取一个obj的值

WBOY
Release: 2016-06-06 20:43:04
Original
1125 people have browsed it

有一物件如下:(xml格式)
[altLineId] => SimpleXMLElement Object
(
[0] => 651382441
)

前面略,都可取到,但这个难倒我了。
对象下有一个数组里面有一个元素key值叫 altLineId
现在我要取出 这个 651382441

已试方式如下

<code>$a=$tmp1['altLineId']=$spreadV['altLineId'][0]; //空白 
$a=$tmp1['altLineId']=$spreadV['altLineId']->0; //错误
$a=$tmp1['altLineId']=$spreadV['altLineId']->[0]; //错误
$a=$tmp1['altLineId']=$spreadV['altLineId']->'0' //错误
$a=$tmp1['altLineId']=$spreadV['altLineId']->['0'] //错误
</code>
Copy after login
Copy after login

求大大解!

回复内容:

有一物件如下:(xml格式)
[altLineId] => SimpleXMLElement Object
(
[0] => 651382441
)

前面略,都可取到,但这个难倒我了。
对象下有一个数组里面有一个元素key值叫 altLineId
现在我要取出 这个 651382441

已试方式如下

<code>$a=$tmp1['altLineId']=$spreadV['altLineId'][0]; //空白 
$a=$tmp1['altLineId']=$spreadV['altLineId']->0; //错误
$a=$tmp1['altLineId']=$spreadV['altLineId']->[0]; //错误
$a=$tmp1['altLineId']=$spreadV['altLineId']->'0' //错误
$a=$tmp1['altLineId']=$spreadV['altLineId']->['0'] //错误
</code>
Copy after login
Copy after login

求大大解!

<code class="lang-php">$a = $tmp1['altLineId'] = $spreadV['altLineId']->{0}; 
</code>
Copy after login

我记得如果是SimpleXML解析的话直接用 $spreadV->altLineId 就可以获取到第一个值了吧,如果是多个的话就用foreach($spreadV->altLineId as $lineId){}好了。而且有点想吐槽你的标签,明明是XML解析结果给了一个JSONObject的标签。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template