在php中获取数组值

时间:2015-05-29 05:38:48

标签: php multidimensional-array

这是我想要mc_gross值的数组。请帮忙

Array
(
    [id] => 5
    [txn_id] => 1fadfa1sfsa2
    [log] => Array
(
    [mc_gross] => 298.44
    [invoice] => 0856545471323
    [protection_eligibility] => Eligible
    [address_status] => confirmed
    [item_number1] => 12299
    [payer_id] => UTU3f7TLQ6DLX4
    [tax] => 0.00
    [address_street] => 1 Main St
    [payment_date] => 02:10:29 May 28, 2015 PDT
    [payment_status] => Completed
    [charset] => windows-1252
    [address_zip] => 95131
    [mc_shipping] => 0.00
    [mc_handling] => 0.00
    [first_name] =>Rohit
    [mc_fee] => 8.95
    [address_country_code] => US
    [address_name] => Rohit
    [notify_version] => 3.8
    [custom] => 
    [payer_status] => verified
    [business] => sunny@gmail.com
    [address_country] => United States
    [num_cart_items] => 1
    [mc_handling1] => 0.00
    [address_city] => San Jose
    [verify_sign] => AHr7LP.QXtufNfq97cbEdHHkqfNkJAtdXVkTwL.GBwGZwJBQ5GAJaqaXx
    [payer_email] => rohit@hotmail.com
    [mc_shipping1] => 0.00
    [tax1] => 0.00
    [txn_id] => 1FV62057CK3146235
    [payment_type] => instant
    [last_name] => Vishwakarma
    [address_state] => CA
    [item_name1] => Centro Yas Island Rotana - Demo
    [receiver_email] => sunny@gmail.com
    [payment_fee] => 8.95
    [quantity1] => 1
    [receiver_id] => 6Y6GRJS8NA8JE
    [txn_type] => cart
    [mc_gross_1] => 298.44
    [mc_currency] => USD
    [residence_country] => US
    [test_ipn] => 1
    [transaction_subject] => 
    [payment_gross] => 298.44
    [ipn_track_id] => 8656eb7f3009dd4
)

    [posted_date] => 2015-05-28 09:10:34
)

7 个答案:

答案 0 :(得分:2)

您可以简单地将其视为

echo $array_name['log']['mc_gross'];

答案 1 :(得分:1)

$VARIABLE_NAME['log']['mc_gross']

您可以将其输出为:

echo $VARIABLE_NAME['log']['mc_gross'];

答案 2 :(得分:1)

试试这个

echo $array_name["log"]["mc_gross"];

答案 3 :(得分:1)

请使用:

$YOUR_VARIABLE['log']['mc_gross']

答案 4 :(得分:0)

$arr= Array
(
    [id] => 5
    [txn_id] => 1fadfa1sfsa2
    [log] => Array
(
    [mc_gross] => 298.44
    [invoice] => 0856545471323
    [protection_eligibility] => Eligible
    [address_status] => confirmed
    [item_number1] => 12299
    [payer_id] => UTU3f7TLQ6DLX4
    [tax] => 0.00
    [address_street] => 1 Main St
    [payment_date] => 02:10:29 May 28, 2015 PDT
    [payment_status] => Completed
    [charset] => windows-1252
    [address_zip] => 95131
    [mc_shipping] => 0.00
    [mc_handling] => 0.00
    [first_name] =>Rohit
    [mc_fee] => 8.95
    [address_country_code] => US
    [address_name] => Rohit
    [notify_version] => 3.8
    [custom] => 
    [payer_status] => verified
    [business] => sunny@gmail.com
    [address_country] => United States
    [num_cart_items] => 1
    [mc_handling1] => 0.00
    [address_city] => San Jose
    [verify_sign] => AHr7LP.QXtufNfq97cbEdHHkqfNkJAtdXVkTwL.GBwGZwJBQ5GAJaqaXx
    [payer_email] => rohit@hotmail.com
    [mc_shipping1] => 0.00
    [tax1] => 0.00
    [txn_id] => 1FV62057CK3146235
    [payment_type] => instant
    [last_name] => Vishwakarma
    [address_state] => CA
    [item_name1] => Centro Yas Island Rotana - Demo
    [receiver_email] => sunny@gmail.com
    [payment_fee] => 8.95
    [quantity1] => 1
    [receiver_id] => 6Y6GRJS8NA8JE
    [txn_type] => cart
    [mc_gross_1] => 298.44
    [mc_currency] => USD
    [residence_country] => US
    [test_ipn] => 1
    [transaction_subject] => 
    [payment_gross] => 298.44
    [ipn_track_id] => 8656eb7f3009dd4
)

    [posted_date] => 2015 to-05-28 09:10:34
)

你可以获得mc_gross值

echo $arr['log']['mc_gross']

答案 5 :(得分:0)

立即试用: 获取mc_gross值

<?php

$array= Array
(
    [id] => 5
    [txn_id] => 1fadfa1sfsa2
    [log] => Array
(
    [mc_gross] => 298.44
    [invoice] => 0856545471323
    [protection_eligibility] => Eligible
    [address_status] => confirmed
    [item_number1] => 12299
    [payer_id] => UTU3f7TLQ6DLX4
    [tax] => 0.00
    [address_street] => 1 Main St
    [payment_date] => 02:10:29 May 28, 2015 PDT
    [payment_status] => Completed
    [charset] => windows-1252
    [address_zip] => 95131
    [mc_shipping] => 0.00
    [mc_handling] => 0.00
    [first_name] =>Rohit
    [mc_fee] => 8.95
    [address_country_code] => US
    [address_name] => Rohit
    [notify_version] => 3.8
    [custom] => 
    [payer_status] => verified
    [business] => sunny@gmail.com
    [address_country] => United States
    [num_cart_items] => 1
    [mc_handling1] => 0.00
    [address_city] => San Jose
    [verify_sign] =>   AHr7LP.QXtufNfq97cbEdHHkqfNkJAtdXVkTwL.GBwGZwJBQ5GAJaqaXx
    [payer_email] => rohit@hotmail.com
    [mc_shipping1] => 0.00
    [tax1] => 0.00
    [txn_id] => 1FV62057CK3146235
    [payment_type] => instant
    [last_name] => Vishwakarma
    [address_state] => CA
    [item_name1] => Centro Yas Island Rotana - Demo
    [receiver_email] => sunny@gmail.com
    [payment_fee] => 8.95
    [quantity1] => 1
    [receiver_id] => 6Y6GRJS8NA8JE
    [txn_type] => cart
    [mc_gross_1] => 298.44
    [mc_currency] => USD
    [residence_country] => US
    [test_ipn] => 1
    [transaction_subject] => 
    [payment_gross] => 298.44
    [ipn_track_id] => 8656eb7f3009dd4
)

    [posted_date] => 2015 to-05-28 09:10:34
)
 ?>

此阵列使用

  <?php
  $value=$array["log"]["mc_gross"];
  echo $value;
?>

OR

 <?php
 foreach($array["log"] => $key=>$value){
  if($key=="mc_gross"){
    echo $value 
  }

 }
<?php

答案 6 :(得分:0)

只需echo $arr['log']['mc_gross']即可获得所需的mc_gross