rofl90 Posted August 14, 2008 Share Posted August 14, 2008 How on earth would I run a foreach on this SimpleXMLElement Object ( [@attributes] => Array ( [stat] => ok [version] => 1.0 ) [venue] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 5597 [name] => [address] => [city] => Chicago [state] => Illinois [zip] => [country] => United States [url] => [description] => [user_id] => 840 [metro_id] => 25 [private] => 0 [latitude] => 41.8498 [longitude] => -87.6482 [geocoding_precision] => city [geocoding_ambiguous] => 0 [state_code] => il [state_id] => 14 [country_code] => us [country_id] => 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 106073 [name] => Champ's Rock Room [address] => 6051 W 79th Street [city] => Burbank [state] => Illinois [zip] => 60459 [country] => United States [url] => [description] => Submitted by <a href="http://eventful.com/venues/V0-001-000502138-0">Eventful.com</a> on behalf of <a href="http://eventful.com/users/voodoopilot">voodoopilot</a>. [user_id] => 190153 [metro_id] => 3518 [private] => 0 [latitude] => 41.7485 [longitude] => -87.7724 [geocoding_precision] => address [geocoding_ambiguous] => 0 [state_code] => il [state_id] => 14 [country_code] => us [country_id] => 1 ) ) I'd like to loop through each set of attributes, ie, if i wanted to do latitude twice + an \n It'd end up as 41.8498 41.7485 Link to comment https://forums.phpfreaks.com/topic/119698-solved-hugely-deep-arrayobject/ Share on other sites More sharing options...
lemmin Posted August 14, 2008 Share Posted August 14, 2008 Try like this: foreach ($xml->venue as $v) { foreach ($v->@attributes as $field => $value) echo $field . " = " . $value; } Link to comment https://forums.phpfreaks.com/topic/119698-solved-hugely-deep-arrayobject/#findComment-616716 Share on other sites More sharing options...
rofl90 Posted August 14, 2008 Author Share Posted August 14, 2008 Parse error: syntax error, unexpected '@', expecting T_STRING or T_VARIABLE or '{' or '$' in /var/www/htdocs/events.php on line 10 which is the @attributes Link to comment https://forums.phpfreaks.com/topic/119698-solved-hugely-deep-arrayobject/#findComment-616721 Share on other sites More sharing options...
Prismatic Posted August 14, 2008 Share Posted August 14, 2008 yay for nested loops <?php $deepArray = array("venue" => array( 0 => array("attributes" => array("latitude" => 41.8498, "stuff" => "things", "blah" => "bleh") ) ), array( 1 => array("attributes" => array("latitude" => 41.6551, "stuff" => "things", "blah" => "bleh") ) ) ); foreach($deepArray as $key => $val) { foreach($val as $VenKey => $VenVal) { foreach($VenVal as $ObKey => $ObVal) { echo $ObVal["latitude"] ."<br>"; } } } ?> produces: 41.8498 41.6551 Link to comment https://forums.phpfreaks.com/topic/119698-solved-hugely-deep-arrayobject/#findComment-616726 Share on other sites More sharing options...
lemmin Posted August 14, 2008 Share Posted August 14, 2008 Parse error: syntax error, unexpected '@', expecting T_STRING or T_VARIABLE or '{' or '$' in /var/www/htdocs/events.php on line 10 which is the @attributes I figured that might happen. Where does that even '@' symbol come from? Is it in the XML? I just tried to test one and it won't parse a tag that starts with '@.' Try {$v->@attributes} instead and see what happens. Or even try it without the '@' and see. Is it possible to take it out of the XML? Link to comment https://forums.phpfreaks.com/topic/119698-solved-hugely-deep-arrayobject/#findComment-616746 Share on other sites More sharing options...
rofl90 Posted August 14, 2008 Author Share Posted August 14, 2008 The nested loop didn't work Heres the XML before simplexml_load_string(); <?xml version="1.0" encoding="UTF-8"?> <rsp stat="ok" version="1.0"> <venue id="144292" name="Starbucks Coffee" address="181 Barrington Rd" city="Roselle" state="Illinois" zip="60172" country="United States" url="" description="Submitted by <a href="http://eventful.com/venues/V0-001-001421460-9">Eventful.com</a> on behalf of <a href="http://eventful.com/users/DJEleven">DJEleven</a>." user_id="126093" metro_id="3236" private="0" latitude="41.9794" longitude="-88.0891" geocoding_precision="city" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="US" country_id="1" /> <venue id="58967" name="North Riverside Mall" address="7501 West Cermark Rd." city="North Riverside" state="Illinois" zip="60546" country="United States" url="" description="" user_id="124768" metro_id="702;1245" private="0" latitude="41.8381" longitude="-87.8209" geocoding_precision="zip" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="32406" name="Thai Classic" address="3332 N Clark St" city="Chicago" state="Illinois" zip="60657" country="United States" url="http://www.thaiclassicrestaurant.com/" description="" user_id="12199" metro_id="25" private="0" latitude="41.9426" longitude="-87.6529" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="69658" name="Long Grove Strawberry Festival" address="Route 53" city="Long Grove" state="Illinois" zip="" country="United States" url="" description="" user_id="134019" metro_id="702;1245;3495" private="0" latitude="" longitude="" geocoding_precision="" geocoding_ambiguous="" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="58961" name="Weasfield Fox Valley Mall" address="195 Fox Valley Centre Drive" city="Aurora" state="Illinois" zip="60504" country="United States" url="" description="" user_id="124768" metro_id="698;702;1245;1304;2094" private="0" latitude="41.7598" longitude="-88.2085" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="83152" name="Cubby Bear Lounge" address="1059 W Addison St" city="Chicago" state="Illinois" zip="60613" country="United States" url="" description="" user_id="4" metro_id="" private="0" latitude="" longitude="" geocoding_precision="" geocoding_ambiguous="" state_code="IL" state_id="1000000" country_code="us" country_id="1000000" /> <venue id="8049" name="Allstate Arena" address="6920 N. Mannheim Rd." city="Rosemont" state="Illinois" zip="60018" country="United States" url="http://www.allstatearena.com/index.html" description="Newly renovated in 1999, the Allstate Arena (formerly the Rosemont Horizon, built in 1979) is one of the crown jewels of the Village of Rosemont. With 18,500 reserved seating capacity and forty-eight skyboxes, the Allstate Arena is one of the largest indoor entertainment facilities in the Chicagoland market. Excellent sight lines from all seat locations, plenty of on-site parking and convenient public transportation make the Allstate Arena the premier entertainment venue." user_id="13649" metro_id="25" private="0" latitude="42.0059" longitude="-87.8849" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="81000" name="Skidmore Dr." address="Skidmore Dr." city="Antioch" state="Illinois" zip="60002" country="United States" url="" description="" user_id="155260" metro_id="702;1245;3495" private="0" latitude="42.479" longitude="-88.0949" geocoding_precision="street" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="158481" name="The Wyndham Hotel" address="633 North St. Clair Street" city="Chicago" state="Illinois" zip="60611" country="United States" url="" description="" user_id="265101" metro_id="25;702;1245" private="0" latitude="41.8935" longitude="-87.6226" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="41961" name="The Vine Pub & Eatery" address="10236 S Ridgeland" city="Chicago Ridge" state="Illinois" zip="60415" country="United States" url="" description="<p>Venue added by <a rel="nofollow" href='http://www.stolenmixtape.com/venues/240'>Stolen Mix Tape</a>.</p>" user_id="23410" metro_id="3518" private="0" latitude="41.7057" longitude="-87.7796" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="15691" name="Al’s Café & Creamery" address="43 Dupage Court" city="Elgin" state="Illinois" zip="60120" country="United States" url="" description="" user_id="33113" metro_id="2094" private="0" latitude="" longitude="" geocoding_precision="" geocoding_ambiguous="" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="199709" name="AMA Chicago Conference Center" address="8655 W Higgins Rd" city="Chicago" state="Illinois" zip="60631" country="United States" url="" description="" user_id="224864" metro_id="25;702;1245" private="0" latitude="41.9872" longitude="-87.8431" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="28173" name="AMC Loews Streets Of Woodfield 20" address="601 North Martingale Road Suite 105" city="Schaumburg" state="Illinois" zip="60173" country="United States" url="" description="in the Streets of Woodfield Mall" user_id="27165" metro_id="25" private="0" latitude="42.0381" longitude="-88.0354" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="28172" name="AMC Cantera 30" address="28250 Diehl Rd." city="Chicago" state="Illinois" zip="60555" country="United States" url="" description="" user_id="27165" metro_id="25" private="0" latitude="41.8021" longitude="-88.1692" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="12163" name="AMC River East" address="322 E. Illinois" city="Chicago" state="Illinois" zip="" country="United States" url="" description="AMC Movie Theater" user_id="12223" metro_id="25" private="0" latitude="41.8911" longitude="-87.6194" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="52903" name="Highland Fellowship Church" address="2250 West Highland Avenue" city="Elgin" state="Illinois" zip="60123" country="United States" url="" description="" user_id="33113" metro_id="2094" private="0" latitude="42.0419" longitude="-88.3258" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="133688" name="The Prodigal Son Coffeehouse" address="St John United Church of Christ, 309 Fifth Street" city="Aurora" state="Illinois" zip="60505" country="United States" url="http://coffeehouse.stjohnuccaurora.org" description="The Prodigal Son Coffeehouse is a community project of the St John UCC Church in Aurora a 501-c-3 non-profit organization." user_id="238834" metro_id="698;702;1245;1304;2094" private="0" latitude="41.7596" longitude="-88.2987" geocoding_precision="city" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="US" country_id="1" /> <venue id="169145" name="Walker Brothers Restaurant" address="200 Marriott Dr" city="Lincolnshire" state="Illinois" zip="60069" country="United States" url="" description="" user_id="4" metro_id="" private="0" latitude="" longitude="" geocoding_precision="" geocoding_ambiguous="" state_code="IL" state_id="1000000" country_code="us" country_id="1000000" /> <venue id="5946" name="American Legion Music Hall" address="1030 Central Street" city="Evanston" state="Illinois" zip="60202" country="United States" url="www.chicagobluegrass.org" description="" user_id="11138" metro_id="25" private="0" latitude="42.0641" longitude="-87.6863" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="162088" name="Delnor-Community Hospital" address="300 Randall Rd" city="Geneva" state="Illinois" zip="60134" country="United States" url="" description="" user_id="4" metro_id="" private="0" latitude="" longitude="" geocoding_precision="" geocoding_ambiguous="" state_code="IL" state_id="1000000" country_code="us" country_id="1000000" /> <venue id="114299" name="Lake Side Cafe" address="1418 W Howard St, at Sheridan Rd" city="Chicago" state="Illinois" zip="60626" country="United States" url="http://www.lake-side-cafe.com/index.html" description="Lake Side Cafe is renowned as Chicago’s fully vegetarian and vegan-friendly organic restaurant. Specializing in delicious, healthy vegetarian cuisine, Lake Side Cafe is dedicated to providing a high-quality certified-organic diet at affordable prices, using nearly 100% preservative and chemical-free ingredients." user_id="212615" metro_id="25;702;1245" private="0" latitude="42.0194" longitude="-87.6666" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="US" country_id="1" /> <venue id="37983" name="Professional Building" address="164 Division St" city="Elgin" state="Illinois" zip="60120" country="United States" url="" description="" user_id="33113" metro_id="2094" private="0" latitude="42.0388" longitude="-88.2831" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="87606" name="Alternative Health Group LLC" address="1834 W North Avenue" city="Chicago" state="Illinois" zip="60622" country="United States" url="" description="Submitted by <a href="http://eventful.com/venues/V0-001-000450561-8">Eventful.com</a> on behalf of <a href="http://eventful.com/users/oprahorse">oprahorse.</a>" user_id="166248" metro_id="25" private="0" latitude="41.9106" longitude="-87.674" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="86778" name="Chicago Sheraton Hotel and Towers" address="301 East North Water Street" city="Chicago" state="Illinois" zip="" country="United States" url="" description="" user_id="150440" metro_id="25;702;1245" private="0" latitude="41.8895" longitude="-87.6202" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="133044" name="Morton Arboretum" address="4100 Il-53" city="Lisle" state="IL" zip="60532" country="United States" url="" description="" user_id="4" metro_id="" private="0" latitude="" longitude="" geocoding_precision="" geocoding_ambiguous="" state_code="IL" state_id="1000000" country_code="US" country_id="1000000" /> <venue id="23643" name="Stratford Square Mall" address="152 Stratford Square" city="Bloomingdale" state="Illinois" zip="" country="United States" url="http://www.stratfordmall.com" description="" user_id="52593" metro_id="25" private="0" latitude="41.9512" longitude="-88.1135" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="28003" name="Navy Pier" address="600 E Grand Av at Lake Michigan" city="Chicago" state="Illinois" zip="60601" country="United States" url="" description="Submitted by <a rel="nofollow" href=http://eventful.com/venues/V0-001-000112545-7>Eventful.com</a> on behalf of <a rel="nofollow" href=http://eventful.com/users/vanderbeeken>vanderbeeken.</a>" user_id="27427" metro_id="25" private="0" latitude="41.8862" longitude="-87.6224" geocoding_precision="zip" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="36433" name="Education Services Center (U46)" address="355 East Chicago Street" city="Elgin" state="Illinois" zip="60120" country="United States" url="" description="In the U-46 headquarters building" user_id="31537" metro_id="2094" private="0" latitude="42.0371" longitude="-88.2778" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="37596" name="A New Leaf" address="1818 North Wells Street" city="Chicago" state="Illinois" zip="" country="United States" url="" description="" user_id="43128" metro_id="25" private="0" latitude="41.915" longitude="-87.635" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="180348" name="Aniko Salon and Spa" address="1109 S Wabash" city="Chicago" state="Illinois" zip="" country="United States" url="" description="" user_id="184333" metro_id="25;702;1245" private="0" latitude="41.8689" longitude="-87.6257" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> <venue id="124153" name="Whiskey Blue" address="172 W. Adams St." city="Chicago" state="Illinois" zip="60603" country="United States" url="" description="Also at Whiskey Sky (W Lakeshore) 644 N. Lakeshore Dr. Chicago, IL 60611 (312) 255-4463 and Whiskey Mexx Kitchen 1015 Rush St. Chicago, IL 60611 (312) 475-0300" user_id="226743" metro_id="25;702;1245" private="0" latitude="41.8795" longitude="-87.633" geocoding_precision="address" geocoding_ambiguous="0" state_code="il" state_id="14" country_code="us" country_id="1" /> </rsp><!-- web2.up.re3.yahoo.com uncompressed/chunked Thu Aug 14 11:22:48 PDT 2008 --> Link to comment https://forums.phpfreaks.com/topic/119698-solved-hugely-deep-arrayobject/#findComment-616836 Share on other sites More sharing options...
rofl90 Posted August 14, 2008 Author Share Posted August 14, 2008 /bump Link to comment https://forums.phpfreaks.com/topic/119698-solved-hugely-deep-arrayobject/#findComment-616940 Share on other sites More sharing options...
rofl90 Posted August 14, 2008 Author Share Posted August 14, 2008 Did it, it was to do with using attributes() as it's a function/method in simplexml $thisObj = simplexml_load_string($return); foreach($thisObj->event as $event) { foreach($event->attributes() as $key => $val) { echo $key,'="',$val,"\"\n"; } echo "\n\n" . 'New Event..' . "\n\n"; } Link to comment https://forums.phpfreaks.com/topic/119698-solved-hugely-deep-arrayobject/#findComment-616957 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.