This question already has answers here:
How to loop through PHP object with dynamic keys [duplicate]
(16 answers)
Closed 3 years ago.
When I print print_r($event_json); it gives me the array below. I need to get just one value from it [type] as in [type] => charge.succeeded (see the top of the array). I tried echo $event_json[0]['type']; but I am getting nothing.
stdClass Object
(
[created] => 1326853478
[livemode] =>
[id] => charge.succeeded_00000000000000
[type] => charge.succeeded
[object] => event
[request] =>
[pending_webhooks] => 1
[api_version] => 2018-10-31
[data] => stdClass Object
(
[object] => stdClass Object
(
[id] => ch_00000000000000
[object] => charge
[amount] => 500
[amount_refunded] => 0
[application] =>
[application_fee] =>
[application_fee_amount] =>
[balance_transaction] => txn_00000000000000
[billing_details] => stdClass Object
(
[address] => stdClass Object
(
[city] =>
[country] =>
[line1] =>
[line2] =>
[postal_code] =>
[state] =>
)
[email] =>
[name] => someemail#yahoo.com
[phone] =>
)
[captured] =>
[created] => 1553691107
[currency] => usd
[customer] => cus_00000000000000
[description] =>
[destination] =>
[dispute] =>
[failure_code] => card_declined
[failure_message] => Your card was declined.
[fraud_details] => stdClass Object
(
[stripe_report] => fraudulent
)
[invoice] =>
[livemode] =>
[metadata] => stdClass Object
(
)
[on_behalf_of] =>
[order] =>
[outcome] => stdClass Object
(
[network_status] => not_sent_to_network
[reason] => merchant_blacklist
[risk_level] => highest
[risk_score] => 98
[seller_message] => Stripe blocked this payment.
[type] => blocked
)
[paid] => 1
[payment_intent] =>
[payment_method_details] => stdClass Object
(
[card] => stdClass Object
(
[brand] => visa
[checks] => stdClass Object
(
[address_line1_check] =>
[address_postal_code_check] =>
[cvc_check] => unavailable
)
[country] => US
[exp_month] => 1
[exp_year] => 2022
[fingerprint] => Gawa768Trrk4fEmb
[funding] => credit
[last4] => 0019
[three_d_secure] =>
[wallet] =>
)
[type] => card
)
[receipt_email] =>
[receipt_number] =>
[receipt_url] => https://pay.stripe.com/receipts/acct_1DU4J1IcP22cq9aQ/ch_1EIbENIcP22cq9aQk7r9xN3u/rcpt_Em9Xy3Ambv1b8QZISOsIHdbxCnLdgup
[refunded] =>
[refunds] => stdClass Object
(
[object] => list
[data] => Array
(
)
[has_more] =>
[total_count] => 0
[url] => /v1/charges/ch_1EIbENIcP22cq9aQk7r9xN3u/refunds
)
[review] =>
[shipping] =>
[source] => stdClass Object
(
[id] => card_00000000000000
[object] => card
[address_city] =>
[address_country] =>
[address_line1] =>
[address_line1_check] =>
[address_line2] =>
[address_state] =>
[address_zip] =>
[address_zip_check] =>
[brand] => Visa
[country] => US
[customer] => cus_00000000000000
[cvc_check] => unavailable
[dynamic_last4] =>
[exp_month] => 1
[exp_year] => 2022
[fingerprint] => Gawa768Trrk4fEmb
[funding] => credit
[last4] => 0019
[metadata] => stdClass Object
(
)
[name] => someemail#yahoo.com
[tokenization_method] =>
)
[source_transfer] =>
[statement_descriptor] =>
[status] => failed
[transfer_data] =>
[transfer_group] =>
)
)
)
What you are seeing is an stdClass Object and not an array. Do like below:
<?php
echo $event_json->type;
i get json in my project and then i have replace some sub array of it and again have to pass it. so, when i decode json and display it with pre tag it's display like this.
Array
(
[callid] => 59538ea658dfa
[action] => config_get
[message] => ok
[data] => Array
(
[config_file] => /cf/conf/config.xml
[config] => Array
(
[filter] => Array
(
[separator] => Array
(
[wan] =>
)
[rule] => Array
(
[0] => Array
(
[id] =>
[tracker] => 1498479412
[type] => pass
[interface] => wan
[ipprotocol] => inet
[tag] =>
[tagged] =>
[max] =>
[max-src-nodes] =>
[max-src-conn] =>
[max-src-states] =>
[statetimeout] =>
[statetype] => keep state
[os] =>
[protocol] => tcp
[source] => Array
(
[any] =>
)
[destination] => Array
(
[any] =>
)
[descr] => Hi manoj2
[updated] => Array
(
[time] => 1498479412
[username] => admin#172.16.1.22
)
[created] => Array
(
[time] => 1498479412
[username] => admin#172.16.1.22
)
)
[1] => Array
(
[statetype] => keep state
[statetimeout] =>
[max-src-states] =>
[max] =>
[tagged] =>
[tag] =>
[ipprotocol] => inet
[interface] => wan
[os] =>
[source] => Array
(
[any] =>
)
[destination] => Array
(
[any] =>
)
[descr] => hi Divyesh
[updated] => Array
(
[username] => admin#192.168.1.100
[time] => 1498301528
)
[created] => Array
(
[username] => admin#192.168.1.100
[time] => 1498301528
)
[type] => pass
[tracker] => 1498301528
[id] =>
[max-src-nodes] =>
[max-src-conn] =>
)
[2] => Array
(
[destination] => Array
(
[any] =>
)
[source] => Array
(
[network] => lan
)
[tracker] => 0100000101
[interface] => lan
[descr] => Default allow LAN to any rule
[ipprotocol] => inet
[type] => pass
)
[3] => Array
(
[destination] => Array
(
[any] =>
)
[source] => Array
(
[network] => lan
)
[tracker] => 0100000102
[interface] => lan
[descr] => Default allow LAN IPv6 to any rule
[ipprotocol] => inet6
[type] => pass
)
)
)
[shaper] =>
[ipsec] =>
[aliases] => Array
(
[alias] => Array
(
[0] => Array
(
[name] => manoj2_alias2
[type] => network
[address] => manoj2_alias3 172.30.2.65/16 172.30.2.51/32
[descr] => descc
[detail] => nfvbg||dfg||asd | asdfg
)
[1] => Array
(
[name] => manoj2_alias3
[type] => host
[address] => tyuty tyu
[descr] => dess
[detail] => tyu||tyu
)
[2] => Array
(
[name] => sdf
[type] => network
[address] => manoj2_alias2
[descr] => afsasf || weriojdg
[detail] => 256418
)
)
)
)
)
)
and i want to just replace portion sub array of [rule] with the.
[rule] => Array
(
[0] => Array
(
[id] =>
[tracker] => 1498479412
[type] => block
[interface] => lan
[ipprotocol] => any
[tag] =>
[tagged] =>
[max] =>
[max-src-nodes] =>
[max-src-conn] =>
[max-src-states] =>
[statetimeout] =>
[statetype] => keep state
[os] =>
[protocol] => tcp/udp
[source] => Array
(
[any] =>
)
[destination] => Array
(
[any] =>
)
[descr] => second option
[updated] => Array
(
[time] => 149844356
[username] => admin#172.16.1.22
)
[created] => Array
(
[time] => 1498479412
[username] => admin#172.16.1.22
)
)
[1] => Array
(
[statetype] => keep state
[statetimeout] =>
[max-src-states] =>
[max] =>
[tagged] =>
[tag] =>
[ipprotocol] => single
[interface] => wan
[os] =>
[source] => Array
(
[any] => 172.31.2.65/24
)
[destination] => Array
(
[any] => manoj2_alias2
)
[descr] => first option
[updated] => Array
(
[username] => admin#192.168.1.100
[time] => 1498301528
)
[created] => Array
(
[username] => admin#192.168.1.100
[time] => 1498301528
)
[type] => pass
[tracker] => 1498301528
[id] =>
[max-src-nodes] =>
[max-src-conn] =>
)
)
how to do it please help me. i tried but not any success.
Access your array element and assign the new array to it.
$array['data']['config']['filter']['rule'] = $theNewRuleArray;
I am attempting to json_encode an array in php5.3.
json_encode($paperwork_info[0])
The result is bad json. The array is as follows:
[paperwork_guid] => c5bfe512-908d-c513-5a5e-e3a2fbb5548b
[name] => recycle
[sections] => Array
(
[0] => header
[1] => customer
[2] => scope_bullets
[3] => product
[4] => signature
[5] => installer
[6] => order_data
)
[data] => Array
(
[header] => Array
(
[image] => Array
(
[src] => recycle.png
[format] => float:left
)
)
[customer] => Array
(
[f_name] => TEST ONLY
[l_name] => NEIMEIER
[middle_name] => none
[title] => none
[address1] => 28 OEHMAN BLVD
[address2] =>
[address3] =>
[zip] => 14225
[city] => BUFFALO
[state_abbrev] => NY
[email_address] => DALE.NEIMEIER#INSTALLS.COM
[phones] => Array
(
[alt] =>
[cell] =>
[work] =>
[home] => 7165551212
)
)
[scope_bullets] => Array
(
[sku_3001] => Array
(
[bullet_0] => Array
(
[paperwork_bullet_obj_guid] => 2ebefa96-6f6b-069e-e194-245d138b9845
[ordering] => 1
[bullet_text] => This is bullet point #1
[child_level] => 1
[formatting] => Array
(
[0] => Array
(
[start_word] => 2
[num_words] => 0
[tag] => b
[href] =>
)
[1] => Array
(
[start_word] => 2
[num_words] => 1
[tag] => a
[href] => http://www.cnn.com
)
)
)
[bullet_1] => Array
(
[paperwork_bullet_obj_guid] => 734db3f4-01a0-b025-9624-cc52a1845dff
[ordering] => 1
[bullet_text] => Sub-point #1.1
[child_level] => 2
)
[bullet_2] => Array
(
[paperwork_bullet_obj_guid] => ebf5ef02-906e-2005-e499-27eae2edefe9
[ordering] => 1
[bullet_text] => Sub point #1.1.1
[child_level] => 3
)
[bullet_3] => Array
(
[paperwork_bullet_obj_guid] => 447997c1-fd9c-25be-b9bf-39257009fb8b
[ordering] => 1
[bullet_text] => This is bullet point #2
[child_level] => 1
)
[bullet_4] => Array
(
[paperwork_bullet_obj_guid] => 5def2d9c-d322-788c-0afe-d13707004b97
[ordering] => 1
[bullet_text] => Sub point #2.1
[child_level] => 2
)
[bullet_5] => Array
(
[paperwork_bullet_obj_guid] => 84936151-65a3-bcca-951f-b69ff16d34ec
[ordering] => 2
[bullet_text] => Sub point #2.2
[child_level] => 2
)
)
[sku_4405] =>
)
[product] => Array
(
[0] => Array
(
[model] => Paperwork Test abc123
[serial] => 777333
[weight] => 26
[size] =>
[width] =>
[height] => 32
[num_boxes] => 1
[product_name] =>
[sku] =>
[model_number] =>
[part_number] =>
[serial_number] =>
[cat_value] => Best Buy Equipment
[product] =>
[product_type] =>
[product_size] =>
[category] =>
)
)
[signature] => Array
(
[date] => 2016-06-15
[need_customer] => 1
[need_tech] => 1
[need_store] =>
[need_warehouse] =>
)
[installer] => Array
(
[anum] => 45455
[inst_obj_guid] => fb91cf85-381c-b740-e063-775151743da2
[phone] => (317) 519-0481
[tech_f_name] =>
[tech_l_name] =>
[company_name] => ZICO LLC
[email_address] => ZICOLLC#GMAIL.COM
)
[order_data] => Array
(
[assigned_date] => 2016-06-07 22:24:47-04
[purchased_date] => 2016-06-06
[creation_date] => 2016-06-06
[install_date] => 2016-06-10
[install_time] => 19:00:00
[prescheduled_date] => 1969-12-31
[prom_start_time] => 2016-06-10 08:06:00
[prom_end_time] => 2016-06-10 11:06:00
[client_order_id] => 12365478996325412
[job_num] => 4043269
[campaign_wkord_obj_guid] => a9a8cc0b-d7ef-ac0e-df61-dad41c023cb0
[pos_obj_guid] => 096e38c2-55c3-80cf-0778-23f81f1cf2f6
[inst_obj_guid] => fb91cf85-381c-b740-e063-775151743da2
[client_obj_guid] => 247e893a-3ea4-c544-47b2-f23ff16017c6
[ord_obj_guid] => ae55e034-d7d0-5d13-3dd3-22f99df8ead4
[skus] => Array
(
[0] => Array
(
[job_type_obj_guid] => 8234ca2c-e40e-c48c-befc-7ceac5e9de32
[job_sku] => 3001
[client_sku] =>
[sku_name] => Site Survey
)
[1] => Array
(
[job_type_obj_guid] => a3f60c3b-ad3c-d828-9898-fa200edcd3cd
[job_sku] => 4405
[client_sku] =>
[sku_name] => Home Delivery
)
)
[client_specific_data] =>
)
)
)
The resultant json string is as follows:
{"paperwork_guid":"c5bfe512-908d-c513-5a5e-e3a2fbb5548b","name":"recycle","sections":{"0":"header","1"
:"customer","2":"scope_bullets","3":"product","4":"signature","5":"installer","6":"order_data"},"data"
:{"header":{"image":{"src":"recycle.png","format":"float:left"}},"customer":{"f_name":"TEST ONLY","l_name"
:"NEIMEIER","middle_name":"none","title":"none","address1":"28 OEHMAN BLVD","address2":"","address3"
:null,"zip":"14225","city":"BUFFALO","state_abbrev":"NY","email_address":"DALE.NEIMEIER#INSTALLS.COM"
,"phones":{"alt":"","cell":"","work":"","home":"7165551212"}},"scope_bullets":{"sku_3001":{"bullet_0"
:{"paperwork_bullet_obj_guid":"2ebefa96-6f6b-069e-e194-245d138b9845","ordering":"1","bullet_text":"This
is bullet point #1","child_level":"1","formatting":{"0":{"start_word":"2","num_words":"0","tag":"b"
,"href":""},"1":{"start_word":"2","num_words":"1","tag":"a","href":"http:\/\/www.cnn.com"}}},"bullet_1"
:{"paperwork_bullet_obj_guid":"734db3f4-01a0-b025-9624-cc52a1845dff","ordering":"1","bullet_text":"Sub-point
#1.1","child_level":"2"},"bullet_2":{"paperwork_bullet_obj_guid":"ebf5ef02-906e-2005-e499-27eae2edefe9"
,"ordering":"1","bullet_text":"Sub point #1.1.1","child_level":"3"},"bullet_3":{"paperwork_bullet_obj_guid"
:"447997c1-fd9c-25be-b9bf-39257009fb8b","ordering":"1","bullet_text":"This is bullet point #2","child_level"
:"1"},"bullet_4":{"paperwork_bullet_obj_guid":"5def2d9c-d322-788c-0afe-d13707004b97","ordering":"1","bullet_text"
:"Sub point #2.1","child_level":"2"},"bullet_5":{"paperwork_bullet_obj_guid":"84936151-65a3-bcca-951f-b69ff16d34ec"
,"ordering":"2","bullet_text":"Sub point #2.2","child_level":"2"}},"sku_4405":null},"product":{"0":{"model"
:"Paperwork Test abc123","serial":"777333","weight":"26","size":null,"width":null,"height":"32","num_boxes"
:"1","product_name":null,"sku":null,"model_number":null,"part_number":null,"serial_number":null,"cat_value"
:"Best Buy Equipment","product":null,"product_type":null,"product_size":null,"category":null}},"signature"
:{"date":"2016-06-15","need_customer":true,"need_tech":true,"need_store":false,"need_warehouse":false
},"installer":{"anum":"45455","inst_obj_guid":"fb91cf85-381c-b740-e063-775151743da2","phone":"(317) 519-0481"
,"tech_f_name":null,"tech_l_name":null,"company_name":"ZICO LLC","email_address":"ZICOLLC#GMAIL.COM"
},"order_data":{"assigned_date":"2016-06-07 22:24:47-04","purchased_date":"2016-06-06","creation_date"
:"2016-06-06","install_date":"2016-06-10","install_time":"19:00:00","prescheduled_date":"1969-12-31"
,"prom_start_time":"2016-06-10 08:06:00","prom_end_time":"2016-06-10 11:06:00","client_order_id":"12365478996325412"
,"job_num":"4043269","campaign_wkord_obj_guid":"a9a8cc0b-d7ef-ac0e-df61-dad41c023cb0","pos_obj_guid"
:"096e38c2-55c3-80cf-0778-23f81f1cf2f6","inst_obj_guid":"fb91cf85-381c-b740-e063-775151743da2","client_obj_guid"
:"247e893a-3ea4-c544-47b2-f23ff16017c6","ord_obj_guid":"ae55e034-d7d0-5d13-3dd3-22f99df8ead4","skus"
:{"0":{"job_type_obj_guid":"8234ca2c-e40e-c48c-befc-7ceac5e9de32","job_sku":"3001","client_sku":null
,"sku_name":"Site Survey"},"1":{"job_type_obj_guid":"a3f60c3b-ad3c-d828-9898-fa200edcd3cd","job_sku"
:"4405","client_sku":null,"sku_name":"Home Delivery"}},"client_specific_data":""}}}
It appears as though new line feeds are being inserted randomly throughout the josn string. I am not sure if it is just how firebug is outputting the string, but copying-and-pasting the string into jsonLINT produces errors.
Any help would be appreciated.
How would I go about getting the balance from this result?
Braintree_Customer Object
(
[_attributes:protected] => Array
(
[id] => 425865
[merchantId] => abcddeff
[firstName] => Waka
[lastName] => Flaka
[company] => Waka Flaka Co.
[email] => demoemail#gmail.com
[phone] => 281.330.8004
[fax] => 419.555.1235
[website] => http://example.com
[createdAt] => DateTime Object
(
[date] => 2015-11-17 17:57:44.000000
[timezone_type] => 3
[timezone] => UTC
)
[updatedAt] => DateTime Object
(
[date] => 2015-11-17 17:57:44.000000
[timezone_type] => 3
[timezone] => UTC
)
[customFields] =>
[creditCards] => Array
(
[0] => Braintree_CreditCard Object
(
[_attributes] => Array
(
[bin] => 400551
[expirationMonth] => 09
[expirationYear] => 2020
[last4] => 0004
[billingAddress] => Braintree_Address Object
(
[_attributes] => Array
(
[id] => gx
[customerId] => 30007705
[firstName] => Flaka
[lastName] => Waka
[company] =>
[streetAddress] =>
[extendedAddress] =>
[locality] =>
[region] =>
[postalCode] =>
[countryCodeAlpha2] =>
[countryCodeAlpha3] =>
[countryCodeNumeric] =>
[countryName] =>
[createdAt] => DateTime Object
(
[date] => 2015-11-17 17:57:44.000000
[timezone_type] => 3
[timezone] => UTC
)
[updatedAt] => DateTime Object
(
[date] => 2015-11-17 17:57:44.000000
[timezone_type] => 3
[timezone] => UTC
)
)
)
[cardType] => Visa
[cardholderName] => Flaka Waka
[commercial] => Unknown
[countryOfIssuance] =>
[createdAt] => DateTime Object
(
[date] => 2015-11-17 17:57:44.000000
[timezone_type] => 3
[timezone] => UTC
)
[customerId] => 30007705
[customerLocation] => US
[debit] => Yes
[default] => 1
[durbinRegulated] => Yes
[expired] =>
[healthcare] => Unknown
[imageUrl] => https://assets.braintreegateway.com/payment_method_logo/visa.png?environment=sandbox
[issuingBank] => Unknown
[payroll] => Unknown
[prepaid] => No
[subscriptions] => Array
(
[0] => Braintree_Subscription Object
(
[_attributes] => Array
(
[addOns] => Array
(
)
[balance] => 0.00
My code to receive the cardType is
$cardtype = $customer->creditCards[0]->cardType;
You can try this
$balance = $customer->creditCards[0]->subscriptions[0]->balance;
I am using SOAP API for DocuSign. It is demo account.
So, I have created my code based on sendatemplate.php and I use the templatereference class to create my FieldData and this is the result in array
Array ( [0] => TemplateReference Object ( [TemplateLocation] => Server
[Template] => 2ade4fe1-9b7b-49eb-af2e-xxxxxxxxx [Document] =>
[RoleAssignments] => Array ( [0] => TemplateReferenceRoleAssignment Object (
[RoleName] => Signer1 [RecipientID] => 1 ) ) [FieldData] =>
TemplateReferenceFieldData Object ( [DataValues] => Array ( [0] =>
TemplateReferenceFieldDataDataValue Object ( [TabLabel] => Company [Value]
=> Otto ) ) ) [AdditionalTabs] => [Sequence] => [TemplateAttachments] => ) )
I then use the RequestStatusResponse and this is my result:
RequestStatusResponse Object
(
[RequestStatusResult] => EnvelopeStatus Object
(
[RecipientStatuses] => stdClass Object
(
[RecipientStatus] => Array
(
[0] => RecipientStatus Object
(
[Type] => Signer
[Email] => xxxxxx#yahoo.com
[UserName] => xxxxx
[RoutingOrder] => 1
[Sent] => 2015-12-02T22:56:01.317
[Delivered] => 2015-12-02T22:56:13.567
[Signed] =>
[Declined] =>
[DeclineReason] =>
[Status] => Delivered
[RecipientIPAddress] => xxxxxxxx
[ClientUserId] => 1
[AutoNavigation] =>
[IDCheckInformation] =>
[RecipientAuthenticationStatus] =>
[CustomFields] => stdClass Object
(
)
[TabStatuses] => stdClass Object
(
[TabStatus] => Array
(
[0] => TabStatus Object
(
[TabType] => SignHere
[Status] => Active
[XPosition] => 1333
[YPosition] => 964
[Signed] =>
[TabLabel] => Signature 1
[TabName] => Signature
[TabValue] =>
[DocumentID] =>
[PageNumber] =>
[OriginalValue] =>
[ValidationPattern] =>
[RoleName] =>
[ListValues] =>
[ListSelectedValue] =>
[ScaleValue] =>
[CustomTabType] =>
)
[1] => TabStatus Object
(
[TabType] => Custom
[Status] => Active
[XPosition] => 989
[YPosition] => 916
[Signed] =>
[TabLabel] => Address
[TabName] => Address
[TabValue] =>
[DocumentID] =>
[PageNumber] =>
[OriginalValue] =>
[ValidationPattern] =>
[RoleName] =>
[ListValues] =>
[ListSelectedValue] =>
[ScaleValue] =>
[CustomTabType] =>
)
[2] => TabStatus Object
(
[TabType] => FullName
[Status] => Active
[XPosition] => 989
[YPosition] => 872
[Signed] =>
[TabLabel] => Name 1
[TabName] => Name
[TabValue] =>
[DocumentID] =>
[PageNumber] =>
[OriginalValue] =>
[ValidationPattern] =>
[RoleName] =>
[ListValues] =>
[ListSelectedValue] =>
[ScaleValue] =>
[CustomTabType] =>
)
[3] => TabStatus Object
(
[TabType] => Company
[Status] => Active
[XPosition] => 683
[YPosition] => 252
[Signed] =>
[TabLabel] => Company
[TabName] => Company
[TabValue] =>
[DocumentID] =>
[PageNumber] =>
[OriginalValue] =>
[ValidationPattern] =>
[RoleName] =>
[ListValues] =>
[ListSelectedValue] =>
[ScaleValue] =>
[CustomTabType] =>
)
)
)
[RecipientAttachment] =>
[AccountStatus] =>
[EsignAgreementInformation] =>
[FormData] =>
[RecipientId] =>
)
)
)
I don't see my Company values are populated.
Please help!!!
I am using PHP code to do this.