I am workin in PHP/MYSql application. i am geting data in php like follow
[
{
"id": "4",
"rawId": "4",
"displayName": "123 456",
"name": {
"familyName": "456",
"formatted": "123 456",
"givenName": "123"
},
"nickname": null,
"phoneNumbers": null,
"emails": null,
"addresses": null,
"ims": [
{
"type": -1,
"value": ".adgjm",
"id": "8",
"pref": false
}
],
"organizations": null,
"birthday": null,
"note": null,
"photos": null,
"categories": null,
"urls": null
},
{
"id": "5",
"rawId": "5",
"displayName": "Dooney Evans",
"name": {
"middleName": "",
"familyName": "Evans",
"formatted": "Dooney Evans",
"givenName": "Dooney"
},
"nickname": null,
"phoneNumbers": [
{
"type": "work",
"value": "512-555-1234",
"id": "11",
"pref": false
}
],
"emails": null,
"addresses": null,
"ims": null,
"organizations": null,
"birthday": null,
"note": null,
"photos": null,
"categories": null,
"urls": null
},
{
"id": "18",
"rawId": "18",
"displayName": "John Doe",
"name": {
"familyName": "Doe",
"formatted": "John Doe",
"givenName": "John"
},
"nickname": null,
"phoneNumbers": null,
"emails": null,
"addresses": null,
"ims": null,
"organizations": null,
"birthday": null,
"note": null,
"photos": null,
"categories": null,
"urls": null
},
{
"id": "19",
"rawId": "19",
"displayName": "Rob Doe",
"name": {
"familyName": "Doe",
"formatted": "Rob Doe",
"givenName": "Rob"
},
"nickname": null,
"phoneNumbers": null,
"emails": null,
"addresses": null,
"ims": null,
"organizations": null,
"birthday": null,
"note": null,
"photos": null,
"categories": null,
"urls": null
}
]
Currently it has key in key have may value. may another array, may object and sometimes also array and object goes more nested.
For now i am doing this php to display properly
is there another good or proper way?
$data = json_decode($data);
if(is_array($data))
{
echo '<pre>';
for($i = 0; $i< count($data); $i++)
{
$record = $data[$i];
foreach($record as $key => $value)
{
if($value)
if(is_object($value))
{
foreach($value as $key1 => $value1)
{
echo $key1." = ".$value1."<br />";
}
}
else if (is_array($value))
{
for($j = 0; $j< count($value); $j++)
{
$innerValue = $value[$j];
if(is_object($innerValue))
{
foreach($innerValue as $key1 => $value1)
{
echo $key1." = ".$value1."<br />";
}
}
else if (is_array($innerValue))
{
}
else
{
echo $key." = ".$value."<br />";
}
}
}
else
{
echo $key." = ".$value."<br />";
}
}
//print_r($record);
}
}
You could try using a recursive function, instead of nesting that much:
Pass the function an Array, the output of json_decode($json) for example.
function print_json($json) {
if (is_array($json) || is_object($json)) {
echo "<table width=100%>";
$type = 'Array';
if(is_object($json)) $type = 'Object';
echo '<tr><td colspan=2 style="background-color:#333333;">
<strong><font color=white>'.$type.'</font></strong>
</td></tr>';
foreach ($json as $k => $v) {
echo '<tr><td valign="top" style="background-color:#F0F0F0;">';
echo '<strong>'.$k.'</strong></td><td>';
print_json($v);
echo "</td></tr>";
}
echo "</table>";
return;
}
echo $json;
}
Run in PHP Fiddle
Related
I have nested JSON in PHP, I am new to PHP and I am unable to read the below-nested JSON. Here is the long JSON file.
<?php
$nestedjson='{
"value": [
{
"name": "POOL1",
"id": "/subscriptions/2xxxx-xxxx-xxxx-xxxx/resourcegroups/XXXX/providers/Microsoft.DesktopVirtualization/hostpools/AZREUSLSHP1",
"type": "Microsoft.DesktopVirtualization/hostpools",
"location": "eastus",
"tags": {
"owner": "Domain",
"department": "TPW",
"workLoadType": "WVD",
"contactName": "testuser1",
"CostBucket": "bucket1"
},
"kind": null,
"properties": {
"friendlyName": null,
"description": "Created through the WVD extension",
"hostPoolType": "Pooled",
"personalDesktopAssignmentType": null,
"applicationGroupReferences": [
"/subscriptions/xxxx-xxxx-xxxx-xxxx/resourcegroups/XXXX/providers/Microsoft.DesktopVirtualization/applicationgroups/AZREUSLSHP1-DAG",
"/subscriptions/xxxx-xxxx-xxxx-xxxx/resourcegroups/XXXX/providers/Microsoft.DesktopVirtualization/applicationgroups/AZREUSFINGRP"
],
"customRdpProperty": "",
"maxSessionLimit": 6,
"loadBalancerType": "BreadthFirst",
"validationEnvironment": false,
"ring": null,
"registrationInfo": {
"expirationTime": null,
"token": null,
"resetToken": false,
"registrationTokenOperation": "None"
},
"vmTemplate": "{\"domain\":\"XXXX\",\"galleryImageOffer\":null,\"galleryImagePublisher\":null,\"galleryImageSKU\":null,\"imageType\":\"CustomImage\",\"imageUri\":null,\"customImageId\":\"/subscriptions/XXXX/resourceGroups/IMAGEGALLERYRG/providers/Microsoft.Compute/galleries/WVDImageGallery3/images/WVDBaseImageDefinition1\",\"namePrefix\":\"AZREUSWVD\",\"osDiskType\":\"StandardSSD_LRS\",\"useManagedDisks\":true,\"vmSize\":{\"id\":\"Standard_B2ms\",\"cores\":2,\"ram\":8},\"galleryItemId\":null}",
"preferredAppGroupType": "Desktop",
"migrationRequest": null,
"cloudPcResource": false,
"startVMOnConnect": false,
"ssoadfsAuthority": null,
"ssoClientId": null,
"ssoClientSecretKeyVaultPath": null,
"ssoSecretType": null,
"objectId": "3a5db190-342d-441e-9798-667079784cbf"
}
},
{
"name": "POOL2",
"id": "/subscriptions/xxxx-xxxx-xxxx-xxxx/resourcegroups/XXXX/providers/Microsoft.DesktopVirtualization/hostpools/AZREUSLSHP2",
"type": "Microsoft.DesktopVirtualization/hostpools",
"location": "eastus",
"tags": {
"owner": "Domain",
"department": "TPW",
"workLoadType": "WVD",
"contactName": "testuser2",
"CostBucket": "bucket2"
},
"kind": null,
"properties": {
"friendlyName": null,
"description": "Created through the WVD extension",
"hostPoolType": "Personal",
"personalDesktopAssignmentType": "Direct",
"applicationGroupReferences": [
"/subscriptions/xxxx-xxxx-xxxx-xxxx/resourcegroups/XXXX/providers/Microsoft.DesktopVirtualization/applicationgroups/AZREUSLSHP2-DAG"
],
"customRdpProperty": "",
"maxSessionLimit": 999999,
"loadBalancerType": "Persistent",
"validationEnvironment": false,
"ring": null,
"registrationInfo": {
"expirationTime": null,
"token": null,
"resetToken": false,
"registrationTokenOperation": "None"
},
"vmTemplate": "{\"domain\":\"domain.com\",\"galleryImageOffer\":\"Windows-10\",\"galleryImagePublisher\":\"microsoftwindowsdesktop\",\"galleryImageSKU\":\"19h2-ent-g2\",\"imageType\":\"Gallery\",\"imageUri\":null,\"customImageId\":null,\"namePrefix\":\"AZREUSWVDP\",\"osDiskType\":\"StandardSSD_LRS\",\"useManagedDisks\":true,\"vmSize\":{\"id\":\"Standard_B2s\",\"cores\":2,\"ram\":4},\"galleryItemId\":\"microsoftwindowsdesktop.windows-1019h2-ent-g2\"}",
"preferredAppGroupType": "Desktop",
"migrationRequest": null,
"cloudPcResource": false,
"startVMOnConnect": false,
"ssoadfsAuthority": null,
"ssoClientId": null,
"ssoClientSecretKeyVaultPath": null,
"ssoSecretType": null,
"objectId": "d187b18a-baa7-4e59-97ad-f84a1f50186e"
}
},
{
"name": "POOL3",
"id": "/subscriptions/xxxx-xxxx-xxxx-xxxx/resourcegroups/AZREUSLSWVDREFRG/providers/Microsoft.DesktopVirtualization/hostpools/ReferenceHostPool",
"type": "Microsoft.DesktopVirtualization/hostpools",
"location": "eastus",
"tags": null,
"kind": null,
"properties": {
"friendlyName": null,
"description": null,
"hostPoolType": "Pooled",
"personalDesktopAssignmentType": null,
"applicationGroupReferences": [
"/subscriptions/xxxx-xxxx-xxxx-xxxx/resourcegroups/AZREUSLSWVDREFRG/providers/Microsoft.DesktopVirtualization/applicationgroups/RefAppGroup"
],
"customRdpProperty": "",
"maxSessionLimit": 5,
"loadBalancerType": "DepthFirst",
"validationEnvironment": false,
"ring": null,
"registrationInfo": {
"expirationTime": null,
"token": null,
"resetToken": false,
"registrationTokenOperation": "None"
},
"vmTemplate": null,
"preferredAppGroupType": "Desktop",
"migrationRequest": null,
"cloudPcResource": false,
"startVMOnConnect": false,
"ssoadfsAuthority": null,
"ssoClientId": null,
"ssoClientSecretKeyVaultPath": null,
"ssoSecretType": null,
"objectId": "1f06e1c3-669e-4227-bb7c-386b634c6c30"
}
}
],
"nextLink": null
}'
I would like to read and print the values of "hostPoolType" from the above JSON, I have tried the below code it didn't work.
$arr = json_decode($nestedjson, true);
$hostpooltype = $arr['properties']['hostPoolType'];
//print_r($hostpooltype);
foreach($hostpooltype as $item)
{
echo $item;
echo '<br>';
}
?>
It's not returning the correct result. Can anyone please help here?
you should run loop for each value key of json array.
use this.
<?php
$arr = json_decode($nestedjson, true);
foreach ($arr['value'] as $newArr){
echo $newArr['properties']['hostPoolType'];
echo '<br>';
}
?>
I have found the solution here.
$arr = json_decode($nestedjson, true);
$hostpooltype = array();
$names = array();
foreach ($arr['value'] as $newArr)
{
$hostpooltype[] = $newArr['properties']['hostPoolType'];
$names[] = $newArr ['name'];
}
// Print the values of the A
foreach($hostpooltype as $value){
echo $value . "<br>";
}
Try to use array_walk function:
$arr = json_decode($nestedjson);
function recursiveWalk($value, $key)
{
if (is_array($value)) {
array_walk($value, "recursiveWalk");
}
if (is_object($value)) {
echo "{$value->properties->hostPoolType}<br>";
}
}
array_walk($arr, "recursiveWalk");
First of all I don't really know how to get the result of json which is so much complicated like this:
{
"SearchTime": 190,
"TotalTime": 190,
"SuggestedResponseType": "Person",
"ResultList": [
{
"__type": "ContactResult",
"TotalCount": 57079,
"Type": "Person",
"Contacts": [
{
"UnitId": 459551,
"Id": "459551S1",
"Name": "John d",
"VisitationAddress": "Lauvha 7, 87820",
"PostAddress": null,
"Value": "74 00 00 00",
"ValueType": "Phone",
"Distance": null,
"Rank": 0,
"BusinessName": null,
"Coordinate": {
"Lat": 64.4595741,
"Lon": 11.55081
},
"Logo": null,
"ContactPoints": [
{
"DisplayValue": "911 00 000",
"Indent": 2,
"Label": "Mobiltelefon",
"MainInfo": false,
"Type": "MobilePhone",
"Value": "91000000"
}
],
"FirstName": null,
"LastName": null,
"OrganizationNumber": null,
"Address": {
"PostAddress": null,
"StreetAddress": {
"CityArea": null,
"Coordinate": {
"Lat": 94.4595741,
"Lon": 71.55081
},
"County": "Tr\u00c3\u00b8ndelag",
"DisplayValue": "Lauvha 7 87820 Spilm",
"Entrance": "",
"HouseNumber": "7",
"Houses": null,
"Municipal": "Namsos",
"PostArea": "Spilm",
"PostCode": "87820",
"Street": "Lauvha"
}
},
"Products": null,
"ProfilePictures": null,
"ContactType": "Person"
},
{
"UnitId": 0,
"Id": "Footer",
"Name": "Vis flere treff",
"VisitationAddress": null,
"PostAddress": null,
"Value": "{\"q\":\"john\",\"type\":\"p\",\"start\":1,\"page\":2}",
"ValueType": null,
"Distance": null,
"Rank": 0,
"BusinessName": null,
"Coordinate": null,
"Logo": null,
"ContactPoints": null,
"FirstName": null,
"LastName": null,
"OrganizationNumber": null,
"Address": null,
"Products": null,
"ProfilePictures": null,
"ContactType": null
}
]
}
],
"Stunts": null
}
Next: How can i get the output: name, VisitationAddress and value from (ContactPoints)to be in correct format using foreach
and rid the
"Name": "Vis flere treff",
"Value": "{\"q\":\"john\",\"type\":\"p\",\"start\":1,\"page\":2}",
in the last line.
You'll need to read up on how to interact with objects and arrays in PHP.
$object->property, $array['key'], $object->array_property[$index]->key, etc.
For your particular case, you need to get your JSON using cURL or file_get_contents() or whatever other method you want. Then you need to decode the response with json_decode().
Once you have your JSON object it's just a matter of checking to see if values exist and outputting them however you want. Notice there are a bunch of arrays inside objects, but something like the following will get you started
<?php
$response = file_get_contents( 'https://zabihullah.com/veg/example.json' );
//$response = '{"SearchTime":190,"TotalTime":190,"SuggestedResponseType":"Person","ResultList":[{"__type":"ContactResult","TotalCount":57079,"Type":"Person","Contacts":[{"UnitId":459551,"Id":"459551S1","Name":"John d","VisitationAddress":"Lauvha 7, 87820","PostAddress":null,"Value":"74 00 00 00","ValueType":"Phone","Distance":null,"Rank":0,"BusinessName":null,"Coordinate":{"Lat":64.4595741,"Lon":11.55081},"Logo":null,"ContactPoints":[{"DisplayValue":"911 00 000","Indent":2,"Label":"Mobiltelefon","MainInfo":false,"Type":"MobilePhone","Value":"91000000"}],"FirstName":null,"LastName":null,"OrganizationNumber":null,"Address":{"PostAddress":null,"StreetAddress":{"CityArea":null,"Coordinate":{"Lat":94.4595741,"Lon":71.55081},"County":"Trøndelag","DisplayValue":"Lauvha 7 87820 Spilm","Entrance":"","HouseNumber":"7","Houses":null,"Municipal":"Namsos","PostArea":"Spilm","PostCode":"87820","Street":"Lauvha"}},"Products":null,"ProfilePictures":null,"ContactType":"Person"},{"UnitId":0,"Id":"Footer","Name":"Vis flere treff","VisitationAddress":null,"PostAddress":null,"Value":"{\"q\":\"john\",\"type\":\"p\",\"start\":1,\"page\":2}","ValueType":null,"Distance":null,"Rank":0,"BusinessName":null,"Coordinate":null,"Logo":null,"ContactPoints":null,"FirstName":null,"LastName":null,"OrganizationNumber":null,"Address":null,"Products":null,"ProfilePictures":null,"ContactType":null}]}],"Stunts":null}';
$json = json_decode( $response );
foreach( $json->ResultList[0]->Contacts as $contact ){
//var_dump( $contact );
if( $contact->Name == 'Vis flere treff' ) continue;
if( !empty( $contact->Name ) ) echo "Name: {$contact->Name}\r\n";
if( !empty( $contact->VisitationAddress ) ) echo "Address: {$contact->VisitationAddress}\r\n";
if( !empty( $contact->Value ) ) echo "Value: ". str_replace(' ', '', $contact->Value) ."\r\n";
echo "\r\n";
}
The result of that is the following:
Name: John d
Address: Lauvha 7, 87820
Value: 91000000
Name: Vis flere treff
You can see an example here: http://sandbox.onlinephpfunctions.com/code/ad6aa7fffaf42a32cb8f5568acb24c157c612467
I am making calls to an API
I have the response as an associative array so that I can use:
$field = $response['nameOfKey'];
However, some of the values for keys are themselves arrays like the following:
{
"Title": "Mr",
"Forenames": "Steve",
"Surname": "Williams",
"CountryOfBirth": 1,
"EmailAddress": "john.doe#email.com",
"EmailType": "Personal",
"BirthDate": "\/Date(632880000000)\/",
"Suffix": null,
"NationalInsuranceNumber": null,
"PrimaryAddress": {
"Address1": "Flat 1",
"Address2": "Oxford Street",
"City": "London",
"County": "London",
"Postcode": "L12456",
"Country": 1
},
"AdditionalAddresses": [
{
"Address1": null,
"Address2": null,
"City": null,
"County": null,
"Postcode": null,
"Country": 0,
"AddressType": 0
}
],
"PrimaryTelephone": {
"Number": "123456789",
"DialingCode": 1,
"TelephoneType": 1
},
"AdditionalTelephone": [
{
"Number": "223456789",
"DialingCode": 2,
"TelephoneType": 2
}
],
"BankAccount": {
"AccountName": "John Doe Account",
"AccountNumber": "123456789",
"SortCode": "123456"
},
"PrimaryCitizenship": {
"CountryOfResidency": 1,
"TaxIdentificationNumber": "AB12CD34EF56"
},
"AdditionalCitizenship": [
{
"CountryOfResidency": 0,
"TaxIdentificationNumber": null
}
],
"ExternalCustomerId": "91",
"ExternalPlanId": "91",
"PlanType": 10
}
So at the moment to get Forename I can just do $forename = $decodedResponse["Forenames"]; but I'm quite baffled at trying to get values from the inner arrays.
I thought I could do something like this:
foreach($decodedResponse as $data)
{
foreach($data['TelephoneNumbers'] as $tel)
{
echo $tel['Number']; die();
}
}
Essentially loop through the original Associative array and then loop through a specific key to get its values.
Your should use foreach for following array items: AdditionalAddresses, AdditionalTelephone and AdditionalCitizenship. Otherwise just chain array keys. See examples:
$forename = $decodedResponse['Forenames'];
$address2 = $decodedResponse['PrimaryAddress']['Address2'];
foreach ($decodedResponse['AdditionalTelephone'] as $tel) {
echo $tel['Number'];
}
I have done a query for getting all data's under same id from other table.There are more than 2 data's under same id.
I need to display all data 's under same id like an array.
Here is my sql query:
"SELECT incident.*,entry.*,fighter.*
FROM register_incident AS incident JOIN
register_entry_points AS entry
ON entry.incident_id = incident.incident_id
JOIN add_fire_fighters AS fighter
ON entry.entrypoint_id = fighter.entry_point_id
WHERE incident.incident_id=:incident_id"
I get a response like,
"data":[
{
"incident_id": "5",
"user_id": null,
"entrypoint_id": "20",
"entry_points": "New Entry1111",
"comments": "Comment1",
"fighter_id": "67",
"entry_point_id": "20",
"cylpressure": null,
"time_in": null,
"time_out": null,
"duration": null,
"notes": null
},
{
"incident_id": "5",
"user_id": "16",
"entrypoint_id": "20",
"entry_points": "New Entry1111",
"comments": "Comment1",
"fighter_id": "68",
"entry_point_id": "20",
"cylpressure": "300",
"time_in": "10:30:00",
"time_out": "11:45:00",
"duration": "01:15",
"notes": "Test"
},
But i need to display it like,
"data": [
{
"incident_id": "5",
"user_id": null,
"entrypoint_id": "20",
"entry_points": "New Entry1111",
"comments": "Comment1",
"fighter":{
{
"fighter_id": "67",
"entry_point_id": "20",
"cylpressure": null,
"time_in": null,
"time_out": null,
"duration": null,
"notes": null
},
{
"fighter_id": "68",
"entry_point_id": "20",
"cylpressure": null,
"time_in": null,
"time_out": null,
"duration": null,
"notes": null
}
}
}]
How it is possible?
If I get a ResultSet out of a Query with one or more 1:n relationships, I take the result like this sample.
$Result = array();
foreach($Records as $Record) {
// key 1
$key1 = $Record['incident_id'];
if(isset($Result[$key1])) {
$cuIncident=$Result[$key1];
}
else {
$cuIncident=array(
'incident_id' => $key1,
'user_id' => $Record['user_id'],
//......
'fighter' => array()
);
$Result[$key1] = $cuIncident;
}
// key 2
$key2 = $Record['fighter_id'];
if(isset($cuIncident['fighter'][$key2])) {
$cuFighter = $cuIncident['fighter'][$key2];
}
else {
$cuFighter = array(
'fighter_id' => $key2,
'entry_point_id' => $Record['entry_point_id'],
//......
'key3array' => array()
);
$cuIncident['fighter'][$key2] = $cuFighter;
}
// key 3
// ....
If a key is a multi value key, you have to combine these keys like:
$key3 = $Record['key3prop1']."/".$Record['key3prop2'];
if(isset($key3Array[$key3])) ......
I'm trying to find the most efficient way to return the productID if I supply an id. For example: If I supply the id 17879, how can I get php to return the productID 12550
What I have is below, but I figure there has to be a way to do it.
Thanks in advance for any suggestions!
$sub_type = 17879; #Could be any id
$pid = 0;
$json = file_get_contents($url);
$obj = json_decode($json, true);
foreach ($obj as $val) {
if (is_array($val)) {
foreach ($val as $val) {
if (is_array($val)) {
foreach ($val as $val) {
if ($val['id'] == $sub_type)
$pid = $val['productID'];
}
}
}
}
}
echo $pid;
$url supplies the following JSON
{
"meta": {
"time": "Thursday, September 24, 2015 7:43:53 PM",
"statusCode": 200
},
"results": {
"errors": [],
"messages": [],
"data": [
{
"id": 17879,
"productID": 12550,
"name": " Bill of Rights 8.5x11 ",
"description": "",
"hasTemplate": true,
"deliveredPrices": [
{
"description": "FedEx Ground",
"price": 84.4,
"country": null,
"countryCode": null,
"created": "2015-02-25T16:14:49.283"
},
{
"description": "FedEx 3 Day",
"price": 164.4,
"country": null,
"countryCode": null,
"created": "2015-02-25T16:14:49.283"
},
{
"description": "FedEx 2 Day",
"price": 224.4,
"country": null,
"countryCode": null,
"created": "2015-02-25T16:14:49.287"
},
{
"description": "FedEx Overnight PM",
"price": 304.4,
"country": null,
"countryCode": null,
"created": "2015-02-25T16:14:49.287"
}
]
},
{
"id": 17880,
"productID": 12558,
"name": "Annual Client Survey 8.5x11 (5 pages)",
"description": "",
"hasTemplate": true,
"deliveredPrices": [
{
"description": "FedEx Ground",
"price": 84.4,
"country": null,
"countryCode": null,
"created": "2015-02-26T13:34:01.933"
},
{
"description": "FedEx 3 Day",
"price": 164.4,
"country": null,
"countryCode": null,
"created": "2015-02-26T13:34:01.933"
},
{
"description": "FedEx 2 Day",
"price": 224.4,
"country": null,
"countryCode": null,
"created": "2015-02-26T13:34:01.937"
},
{
"description": "FedEx Overnight PM",
"price": 304.4,
"country": null,
"countryCode": null,
"created": "2015-02-26T13:34:01.937"
}
]
},
{
"id": 17881,
"productID": 12559,
"name": "Estate Planning 8.5x11 ",
"description": "",
"hasTemplate": true,
"deliveredPrices": [
{
"description": "FedEx Ground",
"price": 84.4,
"country": null,
"countryCode": null,
"created": "2015-02-26T14:19:09.29"
},
{
"description": "FedEx 3 Day",
"price": 164.4,
"country": null,
"countryCode": null,
"created": "2015-02-26T14:19:09.297"
},
{
"description": "FedEx 2 Day",
"price": 224.4,
"country": null,
"countryCode": null,
"created": "2015-02-26T14:19:09.307"
},
{
"description": "FedEx Overnight PM",
"price": 304.4,
"country": null,
"countryCode": null,
"created": "2015-02-26T14:19:09.317"
}
]
},
.......
You get the idea. It keeps going. =)
Well.. narrowing it down a bit you could sort of jump right into the data array and go from there.
$obj = json_decode($json, true);
$sub_type = 17879;
$pid = 0;
foreach($obj['results']['data'] as $data){
if($data['id'] == $sub_type){
$pid = $data['productID'];
}
}
echo $pid; //12550
Is this what you are looking for? Or did I misunderstand the question?
Assuming that you have decoded the JSON into an associative array called $array, build an array with ID mapped to productID:
$array = json_decode($url, true);
$results = array_column($array['results']['data'], 'productID', 'ID');
echo $results[17879]; //12550
PHP >= 5.5.0 needed for array_column() or use the PHP Implementation of array_column()