php数组得到单个值

时间:2017-11-29 18:45:39

标签: php arrays

我有一个数组:

print_r($response);

将显示:

    Response: Array
(
    [errors] => false
    [return] => Array
        (
            [price_recurring] => 0
            [country_code] => NL
            [invoicemethod] => instant
            [product_id] => 0
            [affiliate] => 
            [number_of_periods] => 1
           [description] => Betaling voor eventid 274
            [period_duration] => 1 month
            [date] => 29/11/2017 19:42
            [order_quantity] => 1
            [vat] => 21
            [amount_total] => 4599
            [total_paused_days] => 0
            [custom] => WEB1511980957x194237
            [emailaddress] => ik@ik.nl
            [amount_affiliate_initial] => 0
            [total] => 45,99 
            [current_status] => completed
            [amount_affiliate_recurring] => 0
            [amount_total_affiliate] => 0
            [id] => 1790226
            [price_initial] => 4599
            [current_number_of_periods] => 1
            [firstname] => 
        )

)

如何提取价值' custom'?

我试过了:

$response = array_shift($response); 
echo $response['custom'];  

但它什么都不会显示。我在这做错了什么?我知道我很亲密。

2 个答案:

答案 0 :(得分:0)

你在数组中有一个数组

var chart = AmCharts.makeChart("chartdiv", {
  "categoryField": "CITY",
  "graphs": [{
    "type": "column",
    "valueField": "SUM"
  }]
}

还尝试var_dump(或print_r取决于您的喜好),而不是在尝试导航时回显

$response["return"]["custom"]

会告诉你不仅仅是回显null,它不会打印任何内容

答案 1 :(得分:0)

$response是一个包含两个键errorsreturn的数组。反过来,$response['return']是一个包含多个键的数组,包括custom。因此,要访问custom,您需要引用$response['return']['custom']