2

This is the array i want to mc_gross value. please help

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
)
5
  • Where are you getting the array from? A variable? A method? Commented May 29, 2015 at 5:44
  • What is your variable called? Commented May 29, 2015 at 5:48
  • Also, could you show us the code you're using to retrieve and output the variable? Commented May 29, 2015 at 6:08
  • $row = mysqli_fetch_assoc($result); echo '<pre>'; print_r($row); echo '</pre>'; echo $row['log']['mc_gross']; Commented May 29, 2015 at 6:24
  • What does this get you? var_dump($row['log']); Commented May 29, 2015 at 6:27

7 Answers 7

2

You can simply get it as

echo $array_name['log']['mc_gross'];
Sign up to request clarification or add additional context in comments.

2 Comments

Are you getting any error. If yes than post some more relevant code @rahullodhi
Instead of print_r() try to var_dump() your array
1

Try like this

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

3 Comments

i had already tried this but error is comming "Illegal string offset 'mc_gross'";
$array_name should be an array. The "Illegal string offset" warning you will see if its string instead of an array.
1

Just use this:

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

2 Comments

i had already tried this but error is comming "Illegal string offset 'mc_gross'"
Try $YOUR_VARIABLE['log']->mc_gross then
1
$VARIABLE_NAME['log']['mc_gross']

you can output it as:

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

1 Comment

This wouldn't work. You're missing the log subarray.
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
)

you can get mc_gross value

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

Comments

0

Simply echo $arr['log']['mc_gross'] will get your desired mc_gross value

Comments

0

Try It now: Get a mc_gross value

<?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
)
 ?>

This Array Use

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

OR

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

 }
<?php

3 Comments

foreach($row["log"]as $key => $value){ if($key=="mc_gross"){ echo $value; } } I tried this error is comming Invalid argument supplied for foreach() ;
Post your original array. There might be something else that you were not disclosing
its original array. which is coming from select query

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.