• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php数组的问题

php 搞代码 3年前 (2022-01-23) 14次浏览 已收录 0个评论
文章目录[隐藏]

object(SimpleXMLElement)[1]
public ‘book’ =>
array (size=3)
0 =>
object(SimpleXMLElement)[2]
public ‘@attributes’ =>
array (size=1)

public ‘name’ => string ‘PHP’ (length=3)
public ‘price’ => string ‘20.0’ (length=4)
1 =>
object(SimpleXMLElement)[3]
public ‘@attributes’ =>
array (size=1)

public ‘name’ => string ‘XML’ (length=3)
public ‘price’ => string ‘20.3’ (length=4)
2 =>
object(SimpleXMLElement)[4]
public ‘@attributes’ =>
array (size=1)

public ‘name’ => string ‘C#’ (length=2)
public ‘price’ => string ‘20.1’ (length=4)

$xml = file_get_contents(“book.xml”);(、本文来源gao@!dai!ma.com搞$$代^@码网*搞gaodaima代码
$simple = new SimpleXMLElement($xml);

为什么不能使用$simple[‘book’][‘name’];这样取值,只能使用$simple->book->name这样呢。跪求大神解答下

回复讨论(解决方案)

因为是对象!
你不是也看到有 object(SimpleXMLElement) 吗?
object(SimpleXMLElement) 表示是一个 impleXMLElement 类型的对象

哦 明白了 谢谢大神

$simple = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);//这样就转成数组了

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php数组的问题
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址