2015-05-29 36 views
2

這是我想要mc_gross值的數組。請幫助在php中獲取數組值

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] => [email protected] 
    [address_country] => United States 
    [num_cart_items] => 1 
    [mc_handling1] => 0.00 
    [address_city] => San Jose 
    [verify_sign] => AHr7LP.QXtufNfq97cbEdHHkqfNkJAtdXVkTwL.GBwGZwJBQ5GAJaqaXx 
    [payer_email] => [email protected] 
    [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] => [email protected] 
    [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 
) 
+0

你在哪裏得到從陣列?一個變量?一個方法? –

+0

來自變量 –

+0

你叫什麼變量? –

回答

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

可以輸出爲:

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

這不會起作用.. –

+0

這是行不通的。你錯過了'log'子列表。 –

+0

謝謝@StuartWagner。我修正了這一點。 – David

1

嘗試這樣

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

我已經試過這個,但錯誤是「非法字符串偏移'mc_gross'」; –

+0

'$ array_name'應該是一個數組。 「非法字符串偏移」警告你會看到它的字符串而不是數組。 –

+0

然後閱讀這一個:http://stackoverflow.com/questions/9869150/illegal-string-offset-warning-php – Nitek

2

你可以簡單地把它作爲

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

沒有它沒有運行 –

+0

你是否得到任何錯誤。如果是發佈一些更相關的代碼@rahullodhi –

+0

是錯誤是「非法字符串偏移'mc_gross'」 –

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] => [email protected] 
    [address_country] => United States 
    [num_cart_items] => 1 
    [mc_handling1] => 0.00 
    [address_city] => San Jose 
    [verify_sign] => AHr7LP.QXtufNfq97cbEdHHkqfNkJAtdXVkTwL.GBwGZwJBQ5GAJaqaXx 
    [payer_email] => [email protected] 
    [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] => [email protected] 
    [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'] 
1

只要使用此:

$YOUR_VARIABLE['log']['mc_gross'] 
+0

我已經試過這個,但錯誤正在「非法字符串偏移'mc_gross'「 –

+0

嘗試$ YOUR_VARIABLE ['log'] - > mc_gross然後 – Nitek

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] => [email protected] 
    [address_country] => United States 
    [num_cart_items] => 1 
    [mc_handling1] => 0.00 
    [address_city] => San Jose 
    [verify_sign] => AHr7LP.QXtufNfq97cbEdHHkqfNkJAtdXVkTwL.GBwGZwJBQ5GAJaqaXx 
    [payer_email] => [email protected] 
    [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] => [email protected] 
    [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 
+0

foreach($ row [」log「] as $ key => $ value){ if($ key ==」mc_gross「) {echo_value; echo $ value; } }我試過這個錯誤是提供爲foreach()提供的無效參數; –

+0

發佈您的原始數組。可能還有別的東西,你沒有公開 –

+0

它的原始數組。這是來自選擇查詢 –

0

只需echo $arr['log']['mc_gross']會得到你想要的mc_gross