So I've got a page with some jSON data I want to gather into arrays with cURL. To be precise, cURL when used from a PHP program, not from the command line.
I can do that part well with the following codeblock below:
$token = 'my_token_here';
$headers = ['Authorization: Bearer ' . $token];
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLINFO_HEADER_OUT => true,
CURLOPT_URL => 'https://my.infrastructure.com/api/v1/accounts/search',
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_HTTPHEADER => $headers
]);
$resp = curl_exec($curl);
curl_close($curl);
$data = json_decode($resp);
dd($data);
This will return me a 2D array of all the accounts on the page in the above URL, each array containing an 'account' with variables like ID, name, etc.
The printed output, should I run "print_r($data)", is this:
Array ( [0] => stdClass Object ( [id] => 130375 [name] => 3Lakes [domain] => 3lakes.instructure.com [distance] => [authentication_provider] => google ) [1] => stdClass Object ( [id] => 130376 [name] => 3Lakes - Parents [domain] => 3lakes.instructure.com [distance] => [authentication_provider] => canvas ) [2] => stdClass Object ( [id] => 126425 [name] => 95 Percent Group [domain] => 95percentgroup.instructure.com [distance] => [authentication_provider] => ) [3] => stdClass Object ( [id] => 129409 [name] => AACM [domain] => aacm.instructure.com [distance] => [authentication_provider] => canvas ) [4] => stdClass Object ( [id] => 129272 [name] => Aalen [domain] => aalen.instructure.com [distance] => [authentication_provider] => canvas ) [5] => stdClass Object ( [id] => 129572 [name] => Aaron Cohn Middle School - MCSD [domain] => mcsd.instructure.com [distance] => [authentication_provider] => ldap ) [6] => stdClass Object ( [id] => 128124 [name] => Abilene Christian University [domain] => acu.instructure.com [distance] => [authentication_provider] => ) [7] => stdClass Object ( [id] => 127204 [name] => Abilene Christian University Online [domain] => acuonline.instructure.com [distance] => [authentication_provider] => ) [8] => stdClass Object ( [id] => 130398 [name] => Abington Public Schools [domain] => abington.instructure.com [distance] => [authentication_provider] => canvas ) [9] => stdClass Object ( [id] => 128797 [name] => Academia Virtual [domain] => canvas.academiavirtual.cr [distance] => [authentication_provider] => ) )
Now, instead of doing all that, I just want to collect a single array, where that array has an ID equal to an ID I give it; i.e if I want to find the ID "15", it returns either the array matching that, or null.
I am not sure how, though. I know that, after the query, I can do PHP to comb the retrieved $data and check each, but I want to do this a bit smoother, presumably in the curl_setopt_array area somehow.
Is what I'm trying to do possible in this way? Any advice?