natasha_thomas Posted April 7, 2011 Share Posted April 7, 2011 Folks, How can i extract all the elements from the below Array? Arrayname is: $yahooterms Array ( [ResultSet] => Array ( [Result] => Array ( [0] => calla lily [1] => hair pins [2] => crystal crown [3] => red lingerie [4] => red crystal [5] => red wedding [6] => silver link [7] => necessary objects [8] => hair clip [9] => crystal necklace [10] => bridal wedding [11] => link bracelet [12] => appliques [13] => corsage [14] => organza [15] => swarovski crystal [16] => butterflies [17] => gems [18] => balloons [19] => sewing ) ) ) i am using foreach($yahooterms as $replace) { echo $replace->ResultSet->Result; } But its not working.... Quote Link to comment https://forums.phpfreaks.com/topic/233007-extacting-elements-from-array/ Share on other sites More sharing options...
gizmola Posted April 7, 2011 Share Posted April 7, 2011 Looks like the array you want is nested inside 2 others. So try: foreach $yahooterms['ResultSet']['Result'] as $replace) { echo $replace; } Quote Link to comment https://forums.phpfreaks.com/topic/233007-extacting-elements-from-array/#findComment-1198371 Share on other sites More sharing options...
ManiacDan Posted April 7, 2011 Share Posted April 7, 2011 The arrow syntax $object->var->var is for OBJECT, the bracket syntax $array['key']['key'] is for ARRAYS. You cannot use the object syntax on an array, or the array syntax on an object (unless you implement the proper interfaces for that object). You can, however, have an array of arrays of objects, or an object containing an array. The key is to use the proper operator for the job. Also, you need to start developing with error_reporting turned all the way to E_ALL, so that you'd get the proper error about using an object operator on a non-object. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/233007-extacting-elements-from-array/#findComment-1198384 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.