当前位置: 动力学知识库 > 问答 > 编程问答 >

php - How to retrieve array values into individual variables

问题描述:

I have an API which returns a response in form of an array. I want to extract the elements from this array and save them in my database. I have tried using the explode function but it seems I am missing something. Below is an exact sample response from the retrieve.

Array

(

[Response] => Array

(

[external_reference] => bablaba

[withdraw_request_id] => babalalal

[amount] => bababababa

[status] => ababababab

[message] => ababababa.

[new_balance] => babababa

[amount_sent] => ababababa

[currency_sent] => ababababa

[charge_amount] => ababababa

[charge_currency] => babababa

[currency] => abababaab

)

)

网友答案:

What's the point to duplicate the variables?

When you want to save the amount for exemple use $array['response']['amount']

网友答案:

You have an array Response inside the array $Array. In order to convert array element values into variables. You must navigate inside $Array and inside Response to do so you write : $bigArray['smallArray']['element'].

$external_reference = $Array['Response']['external_reference'];
$withdraw_request_id = $Array['Response']['withdraw_request_id'];
$amount = $Array['Response']['amount'];
$status = $Array['Response']['status'];
$message = $Array['Response']['message'];.
$new_balance = $Array['Response']['new_balance'];
$amount_sent = $Array['Response']['amount_sent'];
$currency_sent = $Array['Response']['currency_sent'];
$charge_amount = $Array['Response']['charge_amount'];
$charge_currency = $Array['Response']['charge_currency'];
$currency = $Array['Response']['currency'];

To learn more about multidimensional arrays read: this

分享给朋友:
您可能感兴趣的文章:
随机阅读: