Reputation: 31
`array(2) {
["result"]=>
object(stdClass)#6 (2) {
["totalResults"]=>
int(10514658)
["products"]=>
array(20) {
[0]=>
object(stdClass)#7 (13) {
["lotNum"]=>
int(1)
["packageType"]=>
string(5) "piece"
["imageUrl"]=>
string(141) "http://g01.a.alicdn.com/kf/HTB1v_x3LpXXXXbDXFXXq6xXFXXXs/Medium-Super-color-Lace-up-Zapato-Mujer-grid-print-font-b-Shoes-b-font-The-Trend.jpg"
["30daysCommission"]=>
string(8) "US $0.02"
["productId"]=>
float(32515275585)
["discount"]=>
string(2) "0%"
["originalPrice"]=>
string(9) "US $41.99"
["productUrl"]=>
string(48) "http://www.aliexpress.com/item//32515275585.html"
["productTitle"]=>
string(128) "Medium, Super color Lace-up Zapato Mujer grid print Shoes The Trend of Female Soft Leisure Sapatos chaussure femme winter basket"
["validTime"]=>
string(10) "2016-04-15"
["volume"]=>
string(1) "1"
["evaluateScore"]=>
string(3) "5.0"
["salePrice"]=>
string(9) "US $41.99"
}
[1]=>
object(stdClass)#8 (13) {
["lotNum"]=>
int(1)
["packageType"]=>
string(5) "piece"
["imageUrl"]=>
string(134) "http://g02.a.alicdn.com/kf/HTB1Llk.IpXXXXasXpXXq6xXFXXXH/All-match-Women-font-b-shoes-b-font-high-canvas-font-b-shoes-b-font-women.jpg"
["30daysCommission"]=>
string(8) "US $0.39"
["productId"]=>
int(944204198)
["discount"]=>
string(2) "0%"
["originalPrice"]=>
string(9) "US $32.40"
["productUrl"]=>
string(46) "http://www.aliexpress.com/item//944204198.html"
["productTitle"]=>
string(118) "Hot selling! lady high canvas shoes summer & winter casual shoes sneakers for women Color block decoration top quality"
["validTime"]=>
string(10) "2016-04-25"
["volume"]=>
string(2) "18"
["evaluateScore"]=>
string(3) "4.9"
["salePrice"]=>
string(9) "US $32.40"
}
[2]=>
object(stdClass)#9 (13) {
["lotNum"]=>
int(1)
["packageType"]=>
string(5) "piece"
["imageUrl"]=>
string(144) "http://g03.a.alicdn.com/kf/HTB1N..tKXXXXXc3XXXXq6xXFXXXV/Slimming-font-b-shoes-b-font-women-fashion-leather-casual-font-b-shoes-b-font-women.jpg"
["30daysCommission"]=>
string(8) "US $1.14"
["productId"]=>
float(32426274938)
["discount"]=>
string(2) "0%"
["originalPrice"]=>
string(9) "US $27.04"
["productUrl"]=>
string(48) "http://www.aliexpress.com/item//32426274938.html"
["productTitle"]=>
string(101) "Free Shipping!Slimming sneakers for women, lady's Fitness Shoes Trendy Health Lady Beauty Swing Shoes"
["validTime"]=>
string(10) "2016-04-11"
["volume"]=>
string(2) "55"
["evaluateScore"]=>
string(3) "4.8"
["salePrice"]=>
string(9) "US $27.04"
}
[3]=>
object(stdClass)#10 (13) {
["lotNum"]=>
int(1)
["packageType"]=>
string(5) "piece"
["imageUrl"]=>
string(160) "http://g02.a.alicdn.com/kf/HTB1t5a9KFXXXXcdXXXXq6xXFXXXN/Hot-Fashion-Women-Genuine-Leather-font-b-Shoes-b-font-Height-Increasing-Platform-Wedge-Sneakers-Low.jpg"
["30daysCommission"]=>
string(8) "US $0.06"
["productId"]=>
int(1717026606)
["discount"]=>
string(2) "0%"
["originalPrice"]=>
string(9) "US $49.58"
["productUrl"]=>
string(47) "http://www.aliexpress.com/item//1717026606.html"
["productTitle"]=>
string(123) "2014 Summer Cutout Shoes Velcro Elevator Color Block Decoration Sneaker Shoes Sport Shoes Casual High-Top Women's Cool Boot"
["validTime"]=>
string(10) "2016-04-01"
["volume"]=>
string(1) "2"
["evaluateScore"]=>
string(3) "5.0"
["salePrice"]=>
string(9) "US $49.58"
}
}
}
["errorCode"]=>
int(20010000)
}`
this is the responce im getting i want to get the values in the base of keys using an loop for each 4 objects i tried many solution posted here but no one is working..
need help please reply! thanks in advance
Upvotes: 0
Views: 1520
Reputation: 24276
$productsTitles = array();
foreach ($result->result->products as $product) {
$productsTitles[] = $product->productTitle;
}
var_dump($productsTitles);
Upvotes: 0
Reputation: 40653
Basically you've got here a nice mixture of arrays and objects. Your outer array of 2 elements contains "results" what you care about and "errorCode".
First of all you need to loop through each result you have, then you need to find the desired field ("imageURL" according to the comment) and save it somewhere (or echo it, it doesn't matter).
I'll assume that your array of objects is called $result
$imageUrls = [];
if (isset($result["results"]) && isset($result["results"]->products) {
foreach ($result["results"]->products as $productObject) {
$imageUrls[] = $productObject->imageUrl;
}
}
print_r($imageUrls); // This just dumps the output, you can do whatever else you want with it.
Upvotes: 1