-1

var_dump($response);

Return: array(6) { ["object"]=> string(4) "list" ["hasMore"]=> bool(false) ["totalCount"]=> int(1) ["limit"]=> int(10) ["offset"]=> int(0) ["data"]=> array(1) { [0]=> array(25) { ["object"]=> string(8) "customer" ["id"]=> string(16) "cus_000004078459" ["dateCreated"]=> string(10) "2018-04-04" ["name"]=> string(19) "sylvio de lima neto" ["email"]=> string(18) "dmsylvio@gmail.com" ["company"]=> NULL ["phone"]=> NULL ["mobilePhone"]=> string(11) "61996441895" ["address"]=> string(23) "Avenida das Araucárias" ["addressNumber"]=> string(4) "1735" ["complement"]=> NULL ["province"]=> string(19) "Sul (Águas Claras)" ["postalCode"]=> string(8) "71936250" ["cpfCnpj"]=> string(11) "05452407197" ["personType"]=> NULL ["deleted"]=> bool(false) ["additionalEmails"]=> NULL ["externalReference"]=> NULL ["notificationDisabled"]=> bool(false) ["canDelete"]=> bool(true) ["canEdit"]=> bool(true) ["city"]=> int(15872) ["state"]=> string(2) "DF" ["country"]=> string(6) "Brasil" ["foreignCustomer"]=> bool(false) } } }

How to acess: ["name"]=> string(19) "sylvio de lima neto"

example:

<?php if (isset($response)): ?>
<?php $json = json_decode($response, true); ?>
<?php if ($json['name']): ?>
    <p>User: <?php echo $json['name']; ?></p>
<?php endif; ?>

1 Answers1

1

The name key is inside the data array, in the first element. You should use $json['data'][0]['name']:

<?php if (isset($response)): ?>
<?php $json = json_decode($response, true); ?>
<?php if (isset($json['data'][0]['name'])): ?>
    <p>User: <?php echo $json['data'][0]['name']; ?></p>
<?php endif; ?>

Will output:

User: sylvio de lima neto
Syscall
  • 19,327
  • 10
  • 37
  • 52