So I have tried that:
$json = json_decode($response, true); echo $json['link'];
but I didn’t get anything as output.
I have this json object:
{"results":[{"title":"Cat | global-selector | Caterpillar","link":"https://www.cat.com/","description":"Cookies are small files that are placed on your computer and retrieved by the website in order to make this website work more efficiently and to better ...English · Français · Turkish","additional_links":[{"text":"Cat | global-selector | Caterpillarhttps://www.cat.com","href":"https://www.cat.com/"},{"text":"English","href":"https://www.cat.com/en_ZA.html"},{"text":"Français","href":"https://www.cat.com/fr_DZ.html"},{"text":"Turkish","href":"https://www.cat.com/tr_TR.html"}],"cite":{}},{"title":"Cat - Wikipedia","link":"https://en.wikipedia.org/wiki/Cat","description":"The cat (Felis catus) is a domestic species of small carnivorous mammal. It is the only domesticated species in the family Felidae and is often referred to ...Species: F. catusKingdom: AnimaliaGenus: FelisClass: MammaliaEvolution · Characteristics · Senses · Behavior","additional_links":[{"text":"Cat - Wikipediahttps://en.wikipedia.org › wiki › Cat","href":"https://en.wikipedia.org/wiki/Cat"},{"text":"Animalia","href":"http://en.wikipedia.org/wiki/Animal"},{"text":"Felis","href":"http://en.wikipedia.org/wiki/Felis"},{"text":"Mammalia","href":"http://en.wikipedia.org/wiki/Mammal"},{"text":"Evolution","href":"https://en.wikipedia.org/wiki/Cat#Evolution"},{"text":"Characteristics","href":"https://en.wikipedia.org/wiki/Cat#Characteristics"},{"text":"Senses","href":"https://en.wikipedia.org/wiki/Cat#Senses"},{"text":"Behavior","href":"https://en.wikipedia.org/wiki/Cat#Behavior"}],"cite":{"domain":"https://en.wikipedia.org › wiki › Cat","span":" › wiki › Cat"}},{"title":"Caterpillar | Caterpillar","link":"https://www.caterpillar.com/","description":"Cat® product offerings include articulated trucks, backhoe loaders, dozers, engines, excavators, generators, motor graders, skid steer loaders and wheel loaders ...","additional_links":[{"text":"Caterpillar | Caterpillarhttps://www.caterpillar.com","href":"https://www.caterpillar.com/"}],"cite":{}},{"title":"cat | Breeds & Facts | Britannica","link":"https://www.britannica.com/animal/cat","description":"Dec 13, 2021 — Cat, domesticated member of the family Felidae, order Carnivora, and the smallest member of that family. Like all felids, cats are ...","additional_links":[{"text":"cat | Breeds & Facts | Britannicahttps://www.britannica.com › animal › cat","href":"https://www.britannica.com/animal/cat"}],"cite":{"domain":"https://www.britannica.com › animal › cat","span":" › animal › cat"}},{"title":"Caterpillar Inc. (CAT) Stock Price, News, Quote & History","link":"https://finance.yahoo.com/quote/CAT/","description":"Find the latest Caterpillar Inc. (CAT) stock quote, history, news and other vital information to help you with your stock trading and investing.","additional_links":[{"text":"Caterpillar Inc. (CAT) Stock Price, News, Quote & Historyhttps://finance.yahoo.com › quote › CAT","href":"https://finance.yahoo.com/quote/CAT/"}],"cite":{"domain":"https://finance.yahoo.com › quote › CAT","span":" › quote › CAT"}},{"title":"Cat | National Geographic","link":"https://www.nationalgeographic.com/animals/mammals/facts/domestic-cat","description":"Domestic Cat · Relationship with Humans. Felis catus has had a very long relationship with humans. · Hunting Abilities. Like their wild relatives, domestic cats ...","additional_links":[{"text":"Cat | National Geographichttps://www.nationalgeographic.com › domestic-cat","href":"https://www.nationalgeographic.com/animals/mammals/facts/domestic-cat"}],"cite":{"domain":"https://www.nationalgeographic.com › domestic-cat","span":" › domestic-cat"}},{"title":"Cat Breeds | Types of Cats | Purina","link":"https://www.purina.com/cats/cat-breeds","description":"American Bobtail Cat BreedAmerican Curl Cat BreedAmerican Shorthair CatAmerican Wirehair Cat BreedBalinese-Javanese Cat BreedBengal CatBirman Cat BreedBombay CatBritish Shorthair Cat BreedBurmese CatChartreux Cat Breed","additional_links":[{"text":"Cat Breeds | Types of Cats | Purinahttps://www.purina.com › Cats","href":"https://www.purina.com/cats/cat-breeds"}],"cite":{"domain":"https://www.purina.com › Cats","span":" › Cats"}},{"title":"Cat Adoption Team | Sherwood Cat Rescue | Cat Adoption ...","link":"https://catadoptionteam.org/","description":"Cat Adoption Team is the largest nonprofit, adoption guarantee cat shelter in the Pacific Northwest. We offer adoption, foster care, and veterinary services ...","additional_links":[{"text":"Cat Adoption Team | Sherwood Cat Rescue | Cat Adoption ...https://catadoptionteam.org","href":"https://catadoptionteam.org/"}],"cite":{}}],"image_results":[],"total":4140000000,"answers":["Do cats fart?","What two animals make a cat?","Why do cats hate water?","Is a cat good pet?"],"ts":2.605560064315796,"device_region":"US","device_type":"desktop"}
So how can I get & list the values of these? I will be very happy if someone can help me with this. I’m begginer with json values :/
Advertisement
Answer
You are returning an array of arrays. You need to access them using an index
$json["results"][0]['link']