Многомерный массив PHP x HasOffers

Я застрял несколько дней с массивом. Я использую HasAffers plataform, я не знаю, знает ли кто-нибудь, но это проблема.

Я настраиваю API-вызов для экспорта некоторых данных из базы данных. Я экспортирую ID и NAME на данный момент, они вошли в массив в функции cURL / JSON. Я вижу многомерный массив в функции print_r (). Но когда я пытаюсь вставить петлю, просто не работай.

Это код вызова API:

<?php // Specify API URL define('HASOFFERS_API_URL', 'https://api.hasoffers.com/Apiv3/json'); // Specify method arguments $args = array( 'NetworkId' => 'xxxxx', 'Target' => 'Offer', 'Method' => 'findAll', 'NetworkToken' => 'xxxx', 'fields' => array( 'id', 'name' ) ); // Initialize cURL $curlHandle = curl_init(); // Configure cURL request curl_setopt($curlHandle, CURLOPT_URL, HASOFFERS_API_URL . '?' . http_build_query($args)); // Make sure we can access the response when we execute the call curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); // Execute the API call $jsonEncodedApiResponse = curl_exec($curlHandle); // Ensure HTTP call was successful if($jsonEncodedApiResponse === false) { throw new \RuntimeException( 'API call failed with cURL error: ' . curl_error($curlHandle) ); } // Clean up the resource now that we're done with cURL curl_close($curlHandle); // Decode the response from a JSON string to a PHP associative array $apiResponse = json_decode($jsonEncodedApiResponse, true); // Make sure we got back a well-formed JSON string and that there were no // errors when decoding it $jsonErrorCode = json_last_error(); if($jsonErrorCode !== JSON_ERROR_NONE) { throw new \RuntimeException( 'API response not well-formed (json error code: ' . $jsonErrorCode . ')' ); } // Print out the response details if($apiResponse['response']['status'] === 1) { // No errors encountered //echo 'API call successful'; echo PHP_EOL; echo print_r($apiResponse['response']['data'], true); echo PHP_EOL; } else { // An error occurred echo 'API call failed (' . $apiResponse['response']['errorMessage'] . ')'; echo PHP_EOL; echo 'Errors: ' . print_r($apiResponse['response']['errors'], true); echo PHP_EOL; } 

И это часть результата этого вызова выше:

 Array ( [521] => Array ( [Offer] => Array ( [id] => 521 [name] => 360 Imprimir - BR ) ) [663] => Array ( [Offer] => Array ( [id] => 663 [name] => 360 Imprimir - BR ) ) [627] => Array ( [Offer] => Array ( [id] => 627 [name] => 360 Imprimir Venda Cartões e Folder - BR ) ) [1048] => Array ( [Offer] => Array ( [id] => 1048 [name] => Aasha - IN ) ) [412] => Array ( [Offer] => Array ( [id] => 412 [name] => ABA - English ) ) [573] => Array ( [Offer] => Array ( [id] => 573 [name] => Aba English - BR ) ) [581] => Array ( [Offer] => Array ( [id] => 581 [name] => Aba English - IT ) ) [575] => Array ( [Offer] => Array ( [id] => 575 [name] => Aba English ES ) ) [579] => Array ( [Offer] => Array ( [id] => 579 [name] => Aba English FR ) ) [577] => Array ( [Offer] => Array ( [id] => 577 [name] => Aba English MX ) ) [224] => Array ( [Offer] => Array ( [id] => 224 [name] => Abrinq ) ) [513] => Array ( [Offer] => Array ( [id] => 513 [name] => Acelerador Digital - BR ) ) [218] => Array ( [Offer] => Array ( [id] => 218 [name] => ActionAid - Apadrinhe Uma Criança ) ) [168] => Array ( [Offer] => Array ( [id] => 168 [name] => ActionAid - Apadrinhe uma criança ) ) [496] => Array ( [Offer] => Array ( [id] => 496 [name] => ActionAid - Apadrinhe Uma Criança Display ) ) [718] => Array ( [Offer] => Array ( [id] => 718 [name] => Adrian - US ) ) [374] => Array ( [Offer] => Array ( [id] => 374 [name] => Agarre ) ) [442] => Array ( [Offer] => Array ( [id] => 442 [name] => Agarre Brasil ) ) [676] => Array ( [Offer] => Array ( [id] => 676 [name] => Aladim Shop - BR ) ) [1050] => Array ( [Offer] => Array ( [id] => 1050 [name] => Alisha - IN ) ) [1259] => Array ( [Offer] => Array ( [id] => 1259 [name] => Alternativa de inversion - ES ) ) [844] => Array ( [Offer] => Array ( [id] => 844 [name] => Amanco - BR ) ) [1313] => Array ( [Offer] => Array ( [id] => 1313 [name] => Apple - AU ) ) [1315] => Array ( [Offer] => Array ( [id] => 1315 [name] => Apple - FI ) ) [1317] => Array ( [Offer] => Array ( [id] => 1317 [name] => Apple - FR ) ) [104] => Array ( [Offer] => Array ( [id] => 104 [name] => Assinatura Premiada - Editora Abril ) ) [134] => Array ( [Offer] => Array ( [id] => 134 [name] => Assine Sky ) ) [1217] => Array ( [Offer] => Array ( [id] => 1217 [name] => Auto - CO ) ) [1215] => Array ( [Offer] => Array ( [id] => 1215 [name] => Auto - MX ) ) [651] => Array ( [Offer] => Array ( [id] => 651 [name] => Avon Revendedora Virtual - BR ) ) [852] => Array ( [Offer] => Array ( [id] => 852 [name] => Ações que pagam dividendos - BR ) ) [680] => Array ( [Offer] => Array ( [id] => 680 [name] => Babbel CPA - BR ) ) [678] => Array ( [Offer] => Array ( [id] => 678 [name] => Babbel CPL - BR ) ) [565] => Array ( [Offer] => Array ( [id] => 565 [name] => Be2 BR ) ) [448] => Array ( [Offer] => Array ( [id] => 448 [name] => Bebedouros ) ) [402] => Array ( [Offer] => Array ( [id] => 402 [name] => Bem Direto ) ) [80] => Array ( [Offer] => Array ( [id] => 80 [name] => Bem Mais Seguro ) ) [398] => Array ( [Offer] => Array ( [id] => 398 [name] => Bidu ) ) [148] => Array ( [Offer] => Array ( [id] => 148 [name] => Big Prêmio - CPC ) ) [418] => Array ( [Offer] => Array ( [id] => 418 [name] => Bio Ritmo - Free Pass (OLD) ) ) [613] => Array ( [Offer] => Array ( [id] => 613 [name] => Bio Ritmo Free Pass - BR ) ) [756] => Array ( [Offer] => Array ( [id] => 756 [name] => Bio Ritmo Summer Pass - BR ) ) [506] => Array ( [Offer] => Array ( [id] => 506 [name] => Bio Ritmo Winterpass ) ) [182] => Array ( [Offer] => Array ( [id] => 182 [name] => Bom Negocio ) ) [60] => Array ( [Offer] => Array ( [id] => 60 [name] => Bora Viagem ) ) [200] => Array ( [Offer] => Array ( [id] => 200 [name] => Brasil Bingo ) ) [56] => Array ( [Offer] => Array ( [id] => 56 [name] => Brastemp ) ) [826] => Array ( [Offer] => Array ( [id] => 826 [name] => Buscar Ead - BR ) ) [635] => Array ( [Offer] => Array ( [id] => 635 [name] => Candidatos ) ) [728] => Array ( [Offer] => Array ( [id] => 728 [name] => Capital Strategy - IT ) ) [284] => Array ( [Offer] => Array ( [id] => 284 [name] => Cappoia ) ) [1193] => Array ( [Offer] => Array ( [id] => 1193 [name] => Captain Vape ) ) [124] => Array ( [Offer] => Array ( [id] => 124 [name] => Carro dos Sonhos ) ) [569] => Array ( [Offer] => Array ( [id] => 569 [name] => Carsystem - BR ) ) [376] => Array ( [Offer] => Array ( [id] => 376 [name] => CarSystem - Parceiro ) ) 

Может ли кто-нибудь помочь мне? Мне нужно поставить этот многомерный массив в цикл. Поместить в select или table.

Благодаря!

Related of "Многомерный массив PHP x HasOffers"

Я предполагаю, что результатом кода, который вы $apiResponse['response']['data'] является значение $apiResponse['response']['data'] . Таким образом, цикл будет:

 foreach ($apiResponse['response']['data'] as $data) { echo $data['Offer']['id'] . ", " . $data['Offer']['name']; } 

Также небольшая рекомендация по отладке такого рода ошибок на непроизводительном сервере – добавьте директиву error_reporting в начало вашего скрипта (или в файл начальной загрузки):

 ini_set('display_errors', 1); error_reporting(E_ALL); 

Таким образом, любые незначительные ошибки, такие как доступ к ключу массива, который не существует, будут немедленно обнаружены.