I am Working with MWS for the first time and hoping to create a program that uses the ListMatchingProducts request to average out the prices of every product that matches a query.
It should be a very simple program, but I am having trouble retrieving data.
First I make the call and get amazon's xml sheet, Then I convert the xml to an array.
Print_R shows that the array looks something like this:
Array ( [ListMatchingProductsResult] => Array ( [Products] => Array ( [Product] => Array ( [0] => Array ( [Identifiers] => Array ( [MarketplaceASIN] => Array ( [MarketplaceId] => ATVPDKIKX0DER [ASIN] => 0786866020 ) ) [AttributeSets] => Array ( [ItemAttributes] => Array ( [Author] => Array ( [0] => Stephen C. Lundin [1] => Harry Paul [2] => John Christensen ) [Binding] => Hardcover [Brand] => Hyperion [Color] => White [Creator] => Ken Blanchard [Edition] => 1 [Feature] => Great product! [ItemDimensions] => Array ( [Height] => 8.25 [Length] => 5.50 [Width] => 0.00 [Weight] => 0.54 ) [IsAdultProduct] => false [Label] => Hyperion [Languages] => Array ( [Language] => Array ( [0] => Array ( [Name] => english [Type] => Published ) [1] => Array ( [Name] => english [Type] => Original Language ) [2] => Array ( [Name] => english [Type] => Unknown ) ) ) [ListPrice] => Array ( **[Amount] => 21.00** [CurrencyCode] => USD ) [Manufacturer] => Hyperion [ManufacturerMaximumAge] => 1188.0 [ManufacturerMinimumAge] => 156.0 [NumberOfItems] => 1 [NumberOfPages] => 110 [PackageDimensions] => Array ( [Height] => 0.65 [Length] => 8.60 [Width] => 5.65 [Weight] => 0.58 ) [PackageQuantity] => 1 [PartNumber] => 9780786866021 [ProductGroup] => Book [ProductTypeName] => ABIS_BOOK [PublicationDate] => 2000-03-08 [Publisher] => Hyperion [ReleaseDate] => 2000-03-08 [SmallImage] => Array ( [URL] => http://ecx.images-amazon.com/images/I/51cHo55tbOL._SL75_.jpg [Height] => 75 [Width] => 47 ) [Studio] => Hyperion [Title] => Fish: A Proven Way to Boost Morale and Improve Results ) ) [Relationships] => Array ( ) [SalesRankings] => Array ( [SalesRank] => Array ( [0] => Array ( [ProductCategoryId] => book_display_on_website [Rank] => 4629 ) [1] => Array ( [ProductCategoryId] => 1043856 [Rank] => 2 ) [2] => Array ( [ProductCategoryId] => 2635 [Rank] => 7 ) [3] => Array ( [ProductCategoryId] => 2637 [Rank] => 18 ) ) ) ) [1] ...
I am trying to access the amount part of the array, as this is the price of the object. Eventually, I will need to access the amount of each product and so a loop will likely come into play, but right now i cannot even access one products sales amount.
Here is the code I have been trying
$value = $array->ListMatchingProductsResult->Products->Product[0]->ListPrice->Amount;
print_r($value);
And it is not working. Even calling print_r on $array->ListMatchingProductsResult is not printing an array.
Any help is greatly appreciated!
Thanks,
Matt
You are almost there. Whatever method you are using to convert the XML to a PHP array however, does just that: It creates an associative array of things, not an object. That is why you cannot access it through the ->element operator, but need to use array indexes ['element']
$value = $array['ListMatchingProductsResult']['Products']['Product'][0]['ListPrice']['Amount'];
If you're ever wondering why you're not getting something back, you can successily shorten above expresion until you do. So if a print_r(...) on above expression returns nothing, just remove one square bracket at a time from that print_r until you do get something back. You then know that the last bracket you removed was the culprit.
Array (
[ListMatchingProductsResult] => Array (
[Products] => Array (
[Product] => Array (
[0] => Array (
[Identifiers] => Array (
[MarketplaceASIN] => Array (
[MarketplaceId] => ATVPDKIKX0DER
[ASIN] => 0786866020
)
)
[AttributeSets] => Array (
[ItemAttributes] => Array (
[Author] => Array (
[0] => Stephen C. Lundin
[1] => Harry Paul
[2] => John Christensen
)
[Binding] => Hardcover
[Brand] => Hyperion
[Color] => White
[Creator] => Ken Blanchard
[Edition] => 1
[Feature] => Great product!
[ItemDimensions] => Array (
[Height] => 8.25
[Length] => 5.50
[Width] => 0.00
[Weight] => 0.54
)
[IsAdultProduct] => false
[Label] => Hyperion
[Languages] => Array (
[Language] => Array (
[0] => Array (
[Name] => english
[Type] => Published
)
[1] => Array (
[Name] => english
[Type] => Original Language
)
[2] => Array (
[Name] => english
[Type] => Unknown
)
)
)
[ListPrice] => Array (
[Amount] => 21.00
[CurrencyCode] => USD
)
[Manufacturer] => Hyperion
...
BTW, using <pre>...</pre> is helpful when trying to make sense of print_r() or var_dump().
P.S. You owe me a new space key.
Here is an sdk library that uses the ListMatchingProducts of Amazon MWS. You will be able to get the info in accessing info required.
https://github.com/choomz/amazon-mws-sdk/blob/master/search/src/MarketplaceWebServiceProducts/Samples/ListMatchingProductsSample.php
To show php errors have this set in your php.in
display_errors = On
You can also give this on top of the php script
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 'On');
Related
I have been trying to extract the following data for each student from a large multidimensional array (Shown further down)
Data -> gender,
Data -> grade,
Data -> name -> first,
Data -> name -> last,
Data -> name -> middle,
Data -> student_number,
Data -> ID
I have tried various options through searching including Slice, Splice, and a for loop.
Every attempt has been met with failure on all or some of the data. I have never been able to get to the 3rd nested data of First, Middle, and Last name.
How can I take a large multidem array like this, and extract the data listed above in a foreach loop so I can import it into a database? I feel like it is alot simpler than I am making it. I have not included any code as I have yet to have anything that seems remotely useful.
Here is a sample array below. Thanks!
Array
(
[data] => Array
(
[0] => Array
(
[data] => Array
(
[gender] => M
[dob] => 7/17/2008
[email] =>
[grade] => 2
[schools] => Array
(
[0] =>12345
)
[school] => 12345
[created] => 2018-04-16T14:01:00.437Z
[name] => Array
(
[first] => Jacob
[last] => Smith
[middle] => Rabbitboom
)
[location] => Array
(
[zip] =>
[address] =>
[city] =>
[lat] =>
[lon] =>
[state] =>
)
[district] => 123456
[last_modified] => 2018-04-16T14:01:00.437Z
[race] =>
[hispanic_ethnicity] =>
[graduation_year] =>
[student_number] => 1234567
[credentials] => Array
(
[district_username] =>
)
[id] => 123456
)
[uri] =>
)
[1] => Array
(
[data] => Array
(
[gender] => F
[dob] => 7/17/2008
[email] =>
[grade] => 2
[schools] => Array
(
[0] =>12346
)
[school] => 12345
[created] => 2018-04-16T14:01:00.437Z
[name] => Array
(
[first] => Jason
[last] => Smith
[middle] => RobesPerrie
)
[location] => Array
(
[zip] =>
[address] =>
[city] =>
[lat] =>
[lon] =>
[state] =>
)
[district] => 123456
[last_modified] => 2018-04-16T14:01:00.437Z
[race] =>
[hispanic_ethnicity] =>
[graduation_year] =>
[student_number] => 1234568
[credentials] => Array
(
[district_username] =>
)
[id] => 123459
)
[uri] =>
)
The easiest approach might be to extract the nested data arrays and loop that:
foreach(array_column($array['data'], 'data') as $data) {
echo $data['gender'];
echo $data['name']['first'];
}
If schools is variable length then you'll need to loop that or implode(', ', $data['schools']).
$data = file_get_contents("https://graph.facebook.com/246179452202174/posts?access_token=TOKEN");
$data = json_decode($data, true);
print_r(array_values($data));
That's my code. It's simple. I can see the data and when I visit the link, it gives me the same info. So that works perfect. Underneath there's some outputs from the api.
Array ( [0] => Array ( [0] => Array ( [id] => 246179452202174_685970631556385 [from] => Array ( [name] => LGB eSports [category] => Sports Team [id] => 246179452202174 ) [message] => We are back! Sorry that we have been silent! But the silence is over! We will soon update you with some breaking news, stay tuned! Do not move your eyes! You do not want to miss this... [privacy] => Array ( [value] => [description] => [friends] => [allow] => [deny] => ) [type] => status [status_type] => mobile_status_update [created_time] => 2016-05-26T13:12:23+0000 [updated_time] => 2016-05-26T13:12:23+0000 [is_hidden] => [is_expired] => [likes] => Array ( [data] => Array ( [0] => Array ( [id] => 1042109789201130 [name] => Fabio Broggi ) [1] => Array ( [id] => 713442998796859 [name] => Christian Bråten ) [2] => Array ( [id] => 1801480580073327 [name] => Paulo Henrique ) [3] => Array ( [id] => 971217726332439 [name] => Benjamin Holm Davidsen ) ) [paging] => Array ( [cursors] => Array ( [before] => MTA0MjEwOTc4OTIwMTEzMAZDZD [after] => OTcxMjE3NzI2MzMyNDM5 ) ) ) )
When I try to echo $data or maybe $data[1] or something like it, it wont work. Also removing array_values gives me a output of "Array" or "ArrayArray".
So how may I print out the data from the api? It wont work, also; how may I fetch the image? I'd like to print the title of the post, and the image. As a link for a feed at my site.
More response code for link:
Array ( [data] => Array ( [0] => Array ( [id] => 246179452202174_685970631556385 [from] => Array ( [name] => LGB eSports [category] => Sports Team [id] => 246179452202174 ) [message] => We are back! Sorry that we have been silent! But the silence is over! We will soon update you with some breaking news, stay tuned! Do not move your eyes! You do not want to miss this... [privacy] => Array ( [value] => [description] => [friends] => [allow] => [deny] => ) [type] => status [status_type] => mobile_status_update [created_time] => 2016-05-26T13:12:23+0000 [updated_time] => 2016-05-26T13:12:23+0000 [is_hidden] => [is_expired] => [likes] => Array ( [data] => Array ( [0] => Array ( [id] => 1042109789201130 [name] => Fabio Broggi ) [1] => Array ( [id] => 713442998796859 [name] => Christian Bråten ) [2] => Array ( [id] => 1801480580073327 [name] => Paulo Henrique ) [3] => Array ( [id] => 971217726332439 [name] => Benjamin Holm Davidsen ) ) [paging] => Array ( [cursors] => Array ( [before] => MTA0MjEwOTc4OTIwMTEzMAZDZD [after] => OTcxMjE3NzI2MzMyNDM5 ) ) ) ) [1] => Array ( [id] => 246179452202174_680011585485623 [from] => Array ( [name] => Yoyo xno [category] => Musician/Band [id] => 281466768681242 ) [to] => Array ( [data] => Array ( [0] => Array ( [name] => LGB eSports [category] => Sports Team [id] => 246179452202174 ) ) ) [message] => GG - Spotify: https://open.spotify.com/track/7tT6XVWfjtpNF8enpFpZT4 [privacy] => Array ( [value] => [description] => [friends] => [allow] => [deny] => ) [type] => status [status_type] => wall_post [created_time] => 2016-05-12T17:33:49+0000 [updated_time] => 2016-05-12T17:33:49+0000 [is_hidden] => [is_expired] => [likes] => Array ( [data] => Array ( [0] => Array ( [id] => 196458690716329 [name] => Funny memes pics ) ) [paging] => Array ( [cursors] => Array ( [before] => MTk2NDU4NjkwNzE2MzI5 [after] => MTk2NDU4NjkwNzE2MzI5 ) ) ) ) [2] => Array ( [id] => 246179452202174_676411742512274 [from] => Array ( [name] => LGB eSports [category] => Sports Team [id] => 246179452202174 ) [message] => Breaking news! Changes in the team. We are sad to announce that Aurora will part ways with Lgb Female. We wish to thank her for the time she spent with us and we wish her all the best for the future. Here's what she says about this herself: "My time with LGB eSports has come to an end. I am extremely thankful for the opportunity to grow within this team, go to amazing places and meet amazing people. I have learnt so much from this experience and I will never forget all the adventures we've had together! I would like to use this moment of change to look back and sincerely thank all my team-mates for this learning experience, Per Lilliefelth for looking after us, our sponsor Intel for taking care of us and LGB eSports for their immense contribution to helping us grow as an all-female team in Counter-Strike. I am certain I will still remain close to the team and look forward to seeing them at many future events. As for myself I am currently a free agent and look forward to continuing my journey as a competitive CS:GO player for many more years to come. Regards, Aurora Lyngdal" [picture] => https://scontent.xx.fbcdn.net/v/t1.0-0/s130x130/13174168_676411742512274_4595019159434717947_n.jpg?oh=dad6bffaf94a2eae60c578d58f7cf8fc&oe=57E7E3F3 [link] => https://www.facebook.com/LGBeSports/photos/a.252900201530099.1073741829.246179452202174/676411742512274/?type=3 [name] => Timeline Photos [icon] => https://www.facebook.com/images/icons/photo.gif [privacy] => Array ( [value] => [description] => [friends] => [allow] => [deny] => ) [type] => photo [status_type] => added_photos [object_id] => 676411742512274 [created_time] => 2016-05-04T15:08:52+0000 [updated_time] => 2016-05-11T20:30:20+0000 [shares] => Array ( [count] => 4 ) [is_hidden] => [is_expired] => [likes] => Array ( [data] => Array ( [0] => Array ( [id] => 1756499731303402 [name] => Antony Giordans ) [1] => Array ( [id] => 196458690716329 [name] => Funny memes pics ) [2] => Array ( [id] => 10205058377778051 [name] => Charmaine Anne D. Better ) [3] => Array ( [id] => 992479757539742 [name] => Yunus Emre Çeker ) [4] => Array ( [id] => 244636029237859 [name] => Roman Hardinger ) [5] => Array ( [id] => 1134092109982746 [name] => Khoa Nguyen ) [6] => Array ( [id] => 525969817592366 [name] => Joseph Turton ) [7] => Array ( [id] => 1152533898100318 [name] => Kristian Sørensen ) [8] => Array ( [id] => 1193252910715325 [name] => Kamil Grochu Groszek ) [9] => Array ( [id] => 1158759100821275 [name] => Ace Kjirkovski ) [10] => Array ( [id] => 10153477966360064 [name]
you must echo this variable
$data[0][0]['message']
I have a working PHP app running in Bluemix that I want to extend to call a RESTful service (Insights for Twitter). I've been able to call the service, retrieve the json body, and use json_decode as follows to create an array:
$insightList = json_decode($guzzleResponse ->getBody(), true);
However, I can't figure out how to get access to the field I'm interested in. I've searched for solution on the web and tried a few approaches that looked promising, but when I tried to integrate them, I couldn't get them to work. I'm a bit of a PHP novice, so if something doesn't work I'm not sure how to proceed.
The json structure is quite complex, with three top-level arrays - search, tweets, and next. I'm interested in the second of these, tweets. It's a pretty complex array - there is one entry per tweet. The field I want right now is tweets.cde.message.body. You can find the full schema here: https://cdeservice.eu-gb.mybluemix.net/rest-api/#!/messages/getTweets
This is the code I have so far:
foreach($insightList as $cde) {
foreach($cde as $message) {
$insight = $message['body'];
if(strlen($insight) > 60) {
$posts[] = array(
'id' => 99999999,
//Temp; remove links from the text
'text' => $insight,
'category' => $insightCategory,
'image' => 'false'
);
}
}
}
Here's a print_r of $insightList:
[search] => Array (
[results] => 28
[current] => 28
)
[tweets] => Array (
[0] => Array (
[cde] => Array (
[author] => Array (
[gender] => male
[parenthood] => Array (
[isParent] => unknown
)
[location] => Array (
[country] =>
)
[maritalStatus] => Array (
[isMarried] => unknown
)
)
[content] => Array (
[sentiment] => Array (
[evidence] => Array ( )
[polarity] => NEUTRAL
)
)
)
[message] => Array (
[postedTime] => 2015-01-13T09:42:16.000Z
[verb] => share
[link] => http://twitter.com/zWDOM/statuses/554936456477933569
[generator] => Array (
[displayName] => Twitter Web Client
[link] => http://twitter.com
)
[body] => RT #VisualSuccess: "Mainframe & Cloud" Magazine wurde soeben publiziert! http://www.twitter.com #zWDOM #Rocket #JohnKnutson_IBM
[favoritesCount] => 0
[objectType] => activity
[actor] => Array (
[summary] => Seit über 25 Jahren im Mainframebereich, derzeit als Senior Consultant und IT Architekt für zEnterprise und Projektmanager beim IBM BP Cancom in Köln
[image] => https://pbs.twimg.com/profile_images/424202233463308288/XQquUcnh_normal.jpeg
[statusesCount] => 2309
[utcOffset] => 3600
[languages] => Array (
[0] => de
)
[preferredUsername] => zWDOM
[displayName] => Willi Domroese
[postedTime] => 2009-12-17T01:39:25.000Z
[link] => http://www.twitter.com/zWDOM
[verified] =>
)
[provider] => Array (
[displayName] => Twitter
[link] => http://www.twitter.com
[objectType] => service
)
[twitter_filter_level] => medium
[twitter_entities] => Array (
[urls] => Array (
[0] => Array (
[display_url] => ln.is/paper.li/visua…
[indices] => Array (
[0] => 77
[1] => 99
)
[expanded_url] => http://ln.is/paper.li/visualsucce/7zYNk
[url] => http://www.twitter.com
)
)
[hashtags] => Array ( )
[user_mentions] => Array (
[0] => Array (
[indices] => Array (
[0] => 3
[1] => 17
)
[screen_name] => VisualSuccess
[id_str] => 213337792
[name] => Predrag Gasic
[id] => 213337792
)
[1] => Array (
[indices] => Array (
[0] => 101
[1] => 107
)
[screen_name] => zWDOM
[id_str] => 97334013
[name] => Willi Domroese
[id] => 97334013
)
[2] => Array (
[indices] => Array (
[0] => 108
[1] => 115
)
[screen_name] => Rocket
[id_str] => 870584947
[name] => Rocket Software
[id] => 870584947
)
[3] => Array (
[indices] => Array (
[0] => 116
[1] => 132
)
[screen_name] => JohnKnutson_IBM
[id_str] => 16452310
[name] => John Knutson
[id] => 16452310
)
)
[trends] => Array ( )
[symbols] => Array ( )
)
[twitter_lang] => de
[id] => tag:search.twitter.com,2005:554936456477933569
[retweetCount] => 1
[gnip] => Array (
[urls] => Array (
[0] => Array (
[expanded_url] => http://linkis.com/paper.li/visualsucce/7zYNk
[expanded_status] => 200
[url] => http://www.twitter.com
)
)
[language] => Array (
[value] => de
)
)
[object] => Array (
[postedTime] => 2015-01-13T08:04:48.000Z
[verb] => post
[link] => http://twitter.com/VisualSuccess/statuses/554911928527888384
[generator] => Array (
[displayName] => Linkis.com
[link] => http://linkis.com
)
[body] => "Mainframe & Cloud" Magazine wurde soeben publiziert! http://www.twitter.com ://www.twitter.com
[objectType] => activity
[actor] => Array (
[summary] => Ù† (N), Wirtschaftsinformatiker | SAP Consultant Logistics #bigdata #appdevelopment #webdesign #eCommerce #SocialMedia #contentmarketing #SmartHome #Journal
[image] => https://pbs.twimg.com/profile_images/2841607223/959b0d23646b1f24bd7b70deac160e2f_normal.jpeg
[statusesCount] => 14185
[utcOffset] => 3600
[languages] => Array (
[0] => de
)
[preferredUsername] => VisualSuccess
[displayName] => Predrag Gasic
[postedTime] => 2010-11-08T17:19:27.000Z
[link] => http://www.twitter.com/VisualSuccess
[verified] =>
)
[provider] => Array (
[displayName] => Twitter
[link] => http://www.twitter.com
[objectType] => service
)
[twitter_filter_level] => low
[twitter_entities] => Array (
[urls] => Array (
[0] => Array (
[display_url] => ln.is/paper.li/visua…
[indices] => Array (
[0] => 58
[1] => 80
)
[expanded_url] => http://ln.is/paper.li/visualsucce/7zYNk
[url] => http://www.twitter.com
)
)
[hashtags] => Array ( )
[user_mentions] => Array (
[0] => Array (
[indices] => Array (
[0] => 82
[1] => 88
)
[screen_name] => zWDOM
[id_str] => 97334013
[name] => Willi Domroese
[id] => 97334013
)
[1] => Array (
[indices] => Array (
[0] => 89
[1] => 96
)
[screen_name] => Rocket
[id_str] => 870584947
[name] => Rocket Software
[id] => 870584947
)
[2] => Array (
[indices] => Array (
[0] => 97
[1] => 113
)
[screen_name] => JohnKnutson_IBM
[id_str] => 16452310
[name] => John Knutson
[id] => 16452310
)
)
[trends] => Array ( )
[symbols] => Array (
)
)
)
)
)
Answers to this question would be greatly appreciated
Iterating $insightList will not get you to the cde level. And you don't actually want the cde; you want the message.
Just iterate the tweets. You don't need a foreach to get keyed info from a PHP array.
foreach($insightList['tweets'] as $tweet) {
$insight = $tweet['message']['body'];
if(strlen($insight) > 60) {
$posts[] = array(
'id' => 99999999,
//Temp; remove links from the text
'text' => $insight,
'category' => $insightCategory,
'image' => 'false'
);
}
}
It looks to me from your print_r that what you want is at:
echo $insightList[0]['message']['body'];
When there's a section like this [some_key], then 'some_key' is an associative array key, and you can access those elements be they additional arrays or a value, using the key name, as I illustrated here.
I'm unable to figure out how to get the values I need from this array ::: the values I need for the 3 vehicles is .
[class] => span3 scrape_img the image Href & image src
[class] => price scrape_price the price
[class] => scrape_make the make
[class] => scrape_year the year
I've tried to figure this out by going through PHP array documentation without much success.
Array
(
[query] => Array
(
[count] => 12
[created] => 2013-02-04T17:46:34Z
[lang] => en-US
[results] => Array
(
[div] => Array
(
[0] => Array
(
[class] => span3 scrape_img
[span] => Array
(
[class] => scrape
[a] => Array
(
[href] => http://cant-reveal-this.com/cars/hyundai/ix35-2-0gls-auto/
[img] => Array
(
[alt] => Featured Image
[src] => /wp-content/uploads/2013/02/01863-270x150.jpg
)
)
)
)
[1] => Array
(
[class] => price scrape_price
[p] => From R249,900
)
[2] => Array
(
[class] => span3 scrape_img
[span] => Array
(
[class] => scrape
[a] => Array
(
[href] => http://cant-reveal-this.com/cars/hyundai/ix35-2-0gls/
[img] => Array
(
[alt] => Featured Image
[src] => /wp-content/uploads/2013/02/1930-270x150.jpg
)
)
)
)
[3] => Array
(
[class] => price scrape_price
[p] => From R239,900
)
[4] => Array
(
[class] => span3 scrape_img
[span] => Array
(
[class] => scrape
[a] => Array
(
[href] => http://cant-reveal-this.com/cars/ford/everest-3-0-tdci-xlt-4/
[img] => Array
(
[alt] => Featured Image
[src] => /wp-content/uploads/2013/02/1876-270x150.jpg
)
)
)
)
[5] => Array
(
[class] => price scrape_price
[p] => From R279,900
)
)
[span] => Array
(
[0] => Array
(
[class] => scrape_make
[strong] => Make
[content] => hyundai
)
[1] => Array
(
[class] => scrape_year
[strong] => Year
[content] => 2011
)
[2] => Array
(
[class] => scrape_make
[strong] => Make
[content] => hyundai
)
[3] => Array
(
[class] => scrape_year
[strong] => Year
[content] => 2011
)
[4] => Array
(
[class] => scrape_make
[strong] => Make
[content] => ford
)
[5] => Array
(
[class] => scrape_year
[strong] => Year
[content] => 2011
)
)
)
)
)
Looks like you were able to figure it out from the comments and the other answer. However, I should clarify that my comments on the question were slightly misleading, so you can disregard them. I actually assumed class referred to PHP objects, when in fact class was simply a key for a string (the array looks to me like some parsed HTML/XML). I realized this when you posted a var_dump() of the array in the comments.
The issue is that the array structure is fairly complicated with all the nesting going on, so it may be difficult to see what's what. In general, I agree with the other answer; debugging with var_dump() is a great way to check. Here's my take on what the answer might be.
Assuming your array variable is $array:
1.
$array['query']['results']['div'][0]['span']['a']['href']
$array['query']['results']['div'][0]['span']['a']['img']['src']
2.
$array['query']['results']['div'][1]['span']['p']
3.
$array['query']['results']['span'][0]['content']
4.
$array['query']['results']['span'][1]['content']
try this:
if this array is in a variable named $array
1-$array['query']['result']['div'][0]['a']['href']
2-$array['query']['result']['div'][1]['p']
3-$array['query']['result']['span'][0]['class']
To debug and find the desired value, try to do like that,
var_dump($array['query']);
then
var_dump($array['query']['result']);
...etc
I need to get the data for each language in it's field as an array.
Probably the best approach in CakePHP will be Set::combine but can't get it working.
I can do it manually with foreach but I don't think that will be the best way.
Here is the example:
Array
(
[Article] => Array
(
[id] => 131
[title] => TEST
)
[titleTranslation] => Array
(
[0] => Array
(
[id] => 62
[locale] => eng
[model] => Article
[foreign_key] => 131
[field] => title
[content] => TEST
)
[1] => Array
(
[id] => 63
[locale] => fre
[model] => Article
[foreign_key] => 131
[field] => title
[content] => Salva
)
[2] => Array
(
[id] => 64
[locale] => rus
[model] => Article
[foreign_key] => 131
[field] => title
[content] => Пвет
)
)
)
into this array:
Array
(
[Article] => Array
(
[id] => 131
[title] => Array
(
[eng] => TEST
[fre] => Salva
[rus] => Пвет
)
)
.... the rest is not important
)
Solved-----
$translatedData = Set::combine($this->data['titleTranslation'], '{n}.locale', '{n}.content', '{n}.field');
$this->data['Article'] = array_merge($this->data['Article'], $translatedData);