PHP simplexml 循环将简单元素放入数组中。我该如何摆脱它?
这就是数组的产生方式,
array(3) { [0]=> string(3) "174" [1]=> object(SimpleXMLElement)#5 (1) { [0]=> string(2) "41" } [2]=> object(SimpleXMLElement)#4 (1) { [0]=> string(2) "21" } }
我在这里使用生成数组的代码。
while($row = mysql_fetch_assoc($results)){
$values[] = $row['id'];
$dom = simplexml_load_file('../data/'.$row['id'].'.xml');
foreach($dom->children() as $child)
{
$values[] = $child->views;
}
}
var_dump($values);
xml 文件看起来像这样
<?xml version="1.0"?>
<website site_id="174" user_id="26">
<view day="23" month="10" year="11">
<views>31</views>
</view>
<view day="23" month="12" year="11">
<views>21</views>
</view>
</website>
我需要将视图的值放入数组中,但我一直遇到这些烦人的问题 数组中的 object(SimpleXMLElement)#5 事物。还有这个 string(3) 。我该如何摆脱那些。 谢谢
This is how the array comes out
array(3) { [0]=> string(3) "174" [1]=> object(SimpleXMLElement)#5 (1) { [0]=> string(2) "41" } [2]=> object(SimpleXMLElement)#4 (1) { [0]=> string(2) "21" } }
I'm using this code here that generates the array.
while($row = mysql_fetch_assoc($results)){
$values[] = $row['id'];
$dom = simplexml_load_file('../data/'.$row['id'].'.xml');
foreach($dom->children() as $child)
{
$values[] = $child->views;
}
}
var_dump($values);
The xml file looks like this
<?xml version="1.0"?>
<website site_id="174" user_id="26">
<view day="23" month="10" year="11">
<views>31</views>
</view>
<view day="23" month="12" year="11">
<views>21</views>
</view>
</website>
I need to get the value of the Views into an array, but I keep getting these annoying
object(SimpleXMLElement)#5 things in the array. Also this string(3) . How do I get rid of those.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
改变
如果您不需要查看变量的类型,
- 只是不要使用
var_dump()
,而是使用print_r()
来解释(字符串):这称为“类型转换”。也适用于其他类型,例如 (int)、(bool) 等。Try to change
with
If you don't need to see the type of the variable - just don't use
var_dump()
, butprint_r()
insteadTo explain (string): This is called 'typecasting'. Also works with other types such as (int), (bool), etc.