二维数组 SimpleXMLElement Object 转换为普通二维数组
程序员文章站
2022-05-15 14:36:14
...
下面为输出的带SimpleXMLElement Object的二维数组,如何能把里面的SimpleXMLElement Object全部去掉变成普通二维数组。
Array ( [0] => SimpleXMLElement Object ( [FavType] => 2 [FreeSum] => 1500 [FreeCurrent] => 965 [FavCode1] => 1 [FavCode2] => 4 [FavOfferInfo] => 201407乐享4G 299元套餐 )
[1] => SimpleXMLElement Object ( [FavType] => 2 [FreeSum] => 500 [FreeCurrent] => 18 [FavCode1] => 1 [FavCode2] => 2 [FavOfferInfo] => 201407乐享4G 299元套餐 )
[2] => SimpleXMLElement Object ( [FavType] => 3 [FreeSum] => 30 [FreeCurrent] => 30 [FavCode1] => 4 [FavCode2] => 8 [FavOfferInfo] => 天翼-集团0元30M后向流量包 )
[3] => SimpleXMLElement Object ( [FavType] => 3 [FreeSum] => 30 [FreeCurrent] => 30 [FavCode1] => 4 [FavCode2] => 8 [FavOfferInfo] => 天翼客服赠送30M省内流量包 )
[4] => SimpleXMLElement Object ( [FavType] => 3 [FreeSum] => 4096 [FreeCurrent] => 1857.32 [FavCode1] => 4 [FavCode2] => 8 [FavOfferInfo] => 201407乐享4G 299元套餐 ) )
Array ( [0] => SimpleXMLElement Object ( [FavType] => 2 [FreeSum] => 1500 [FreeCurrent] => 965 [FavCode1] => 1 [FavCode2] => 4 [FavOfferInfo] => 201407乐享4G 299元套餐 )
[1] => SimpleXMLElement Object ( [FavType] => 2 [FreeSum] => 500 [FreeCurrent] => 18 [FavCode1] => 1 [FavCode2] => 2 [FavOfferInfo] => 201407乐享4G 299元套餐 )
[2] => SimpleXMLElement Object ( [FavType] => 3 [FreeSum] => 30 [FreeCurrent] => 30 [FavCode1] => 4 [FavCode2] => 8 [FavOfferInfo] => 天翼-集团0元30M后向流量包 )
[3] => SimpleXMLElement Object ( [FavType] => 3 [FreeSum] => 30 [FreeCurrent] => 30 [FavCode1] => 4 [FavCode2] => 8 [FavOfferInfo] => 天翼客服赠送30M省内流量包 )
[4] => SimpleXMLElement Object ( [FavType] => 3 [FreeSum] => 4096 [FreeCurrent] => 1857.32 [FavCode1] => 4 [FavCode2] => 8 [FavOfferInfo] => 201407乐享4G 299元套餐 ) )
回复讨论(解决方案)
function ObjectToArray($o) { if(is_object($o)) $o = get_object_vars($o); if(is_array($o)) foreach($o as $k=>$v) $o[$k] = ObjectToArray($v); return $o;}