R
R
Rustam Gatin2016-11-02 13:07:26
PHP
Rustam Gatin, 2016-11-02 13:07:26

How to output certain data from an array that JSON gives?

Friends, there is a web service script for the Armtek auto parts site.
If the answer is positive, it gives an array containing a bunch of different information, how to display the necessary information

<?php
error_reporting(-1);
ini_set('display_errors', 1);

require_once '../config.php';
require_once '../../autoloader.php';

use ArmtekRestClient\Http\Exception\ArmtekException as ArmtekException; 
use ArmtekRestClient\Http\Config\Config as ArmtekRestClientConfig;
use ArmtekRestClient\Http\ArmtekRestClient as ArmtekRestClient; 

try {

    // init configuration 
    $armtek_client_config = new ArmtekRestClientConfig($user_settings);  

    // init client
    $armtek_client = new ArmtekRestClient($armtek_client_config);


    $params = [
        'VKORG'         => '4170'       
        ,'KUNNR_RG'     => '43069963'
        ,'PIN'          => 'GP9A33047C'
        ,'BRAND'        => ''
        ,'QUERY_TYPE'   => ''
        ,'KUNNR_ZA'     => ''
        ,'INCOTERMS'    => ''
        ,'VBELN'        => ''
    ];

    // requeest params for send
    $request_params = [

        'url' => 'search/search',
        'params' => [
            'VKORG'         => !empty($params['VKORG'])?$params['VKORG']:(isset($ws_default_settings['VKORG'])?$ws_default_settings['VKORG']:'')       
            ,'KUNNR_RG'     => isset($params['KUNNR_RG'])?$params['KUNNR_RG']:(isset($ws_default_settings['KUNNR_RG'])?$ws_default_settings['KUNNR_RG']:'')
            ,'PIN'          => isset($params['PIN'])?$params['PIN']:''
            ,'BRAND'        => isset($params['BRAND'])?$params['BRAND']:''
            ,'QUERY_TYPE'   => isset($params['QUERY_TYPE'])?$params['QUERY_TYPE']:''
            ,'KUNNR_ZA'     => isset($params['KUNNR_ZA'])?$params['KUNNR_ZA']:(isset($ws_default_settings['KUNNR_ZA'])?$ws_default_settings['KUNNR_ZA']:'')
            ,'INCOTERMS'    => isset($params['INCOTERMS'])?$params['INCOTERMS']:(isset($ws_default_settings['INCOTERMS'])?$ws_default_settings['INCOTERMS']:'')
            ,'VBELN'        => isset($params['VBELN'])?$params['VBELN']:(isset($ws_default_settings['VBELN'])?$ws_default_settings['VBELN']:'')
            ,'format'       => 'json'
        ]

    ];

    // send data
    $response = $armtek_client->post($request_params);

    // in case of json
    $json_responce_data = $response->json();


} catch (ArmtekException $e) {

    $json_responce_data = $e -> getMessage(); 

}

// 
echo "<h1>Пример вызова поиска</h1>";
echo "<h2>Входные параметры</h2>";
echo "<pre>"; print_r( $request_params ); echo "</pre>"; 
echo "<h2>Ответ</h2>";
echo "<pre>"; print_r( $json_responce_data ); echo "</pre>";
?>

Code link in action
Question:
How to output specific data from an array of all objects such as: BRAND, PRICE for example.
If you can give an example of code, please, I broke my whole head, I program at a very beginner level
PS The documentation is here , but it didn’t give me anything, except for setting up the script

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Doniy, 2016-11-02
@doniys_a

It is possible through array_map

$resp = array_map(function ($next) {
    return [
        'BRAND'  => $next['BRAND'],'PRICE'=>$next['PRICE'],
    ];
}, (array) $json_responce_data->RESP);

var_dump($resp);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question