3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $json = '{ "credit_card": { "cvc": "123", "expiry": { "month": "12", "year": "2019" }, "name": "Julian", "number": "5123450000000008", "token": null }, "amount": "10", "currency": "AUD", "gateway": { "line_of_business": "eWallet", "service": "default", "username": null }, "external_id": "my external id", "reference": "julian test", "remitter_name": null, "request_id": "1529561070", "statement_description": null, "security_id": null }'; $array = json_decode($json, true); function array_filter_recursive($array) { $array = array_filter($array); foreach ($array as $key => $value) { if (!is_array($value)) { continue; } $array = array_filter_recursive($value); } return $array; } var_dump(array_filter_recursive($array));
based on ATJBc
Output for 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.30 - 7.3.0beta1
array(2) { ["line_of_business"]=> string(7) "eWallet" ["service"]=> string(7) "default" }