how to get specific value in JSON array with PHP

779 Views Asked by At

As you see in the image:

enter image description here

I've a array of object I think there is JSON array. I want to get only "productThumbnailUrl" on this array and use that in another way.

Can anyone help me to get this value and store it in a separate variable.

It's has multiple rows on the array. I only want get "productThumbnailUrl".

3

There are 3 best solutions below

0
On BEST ANSWER

You can use For loop to loop json data

for(x in json) {
    console.log(json[x].productThumbnailUrl);
}
1
On

Let's consider your main array is

var products= [your product arr];
products.forEach(
function(product){
console.log(product["productThumbnailUrl"]);
});

it will list your productThumbnailUrls. it will loop through all items.

0
On

var x = JSON.parse('{"productThumbnailUrl": "val1", "key2": "val2", "key3": "val3", "key4": "val4"}');

alert (x['productThumbnailUrl']);

var y = x['productThumbnailUrl'];