3v4l.org

run code in 300+ PHP versions simultaneously
<?php $st = '{"id":"PAY-000000000000000000000000","intent":"sale","state":"approved","cart":"11111111111111111", "payer":{"payment_method":"paypal","status":"VERIFIED","payer_info":{"email":"user@host.com","first_name":"NAME","middle_name":"XXX","last_name":"LNAME", "payer_id":"ZZZZZZZZZZZZZ","country_code":"MD"}},"transactions":[{"amount":{"total":"13.49","currency":"USD","details":[]}, "payee":{"merchant_id":"ZZZZZZZZZZZZZ","email":"PAYER@HOST.com"},"item_list":{"items":[{"name":"Package", "description":"Package","price":"8.49","currency":"USD","quantity":1},{"name":"donate","description":"Donate","price":"5.00", "currency":"USD","quantity":1}]},"related_resources":[{"sale":{"id":"0NRFFFFFFFFFFFFFF","state":"completed","amount":{"total":"13.49", "currency":"USD","details":{"subtotal":"13.49"}},"payment_mode":"INSTANT_TRANSFER","protection_eligibility":"INELIGIBLE","transaction_fee":{"value":"0.89", "currency":"USD"},"parent_payment":"PAY-000000000000000000000000","create_time":"2018-01-01T20:35:19Z","update_time":"2018-01-01T20:35:19Z", "links":[{"href":"https:\/\/api.paypal.com\/v1\/payments\/sale\/00000000000000000","rel":"self","method":"GET"}, {"href":"https:\/\/api.paypal.com\/v1\/payments\/sale\/00000000000000000\/refund","rel":"refund","method":"POST"}, {"href":"https:\/\/api.paypal.com\/v1\/payments\/payment\/PAY-000000000000000000000000","rel":"parent_payment","method":"GET"}]}}]}], "create_time":"2018-01-00T20:35:20Z","links":[{"href":"https:\/\/api.paypal.com\/v1\/payments\/payment\/PAY-000000000000000000000000", "rel":"self","method":"GET"}]}'; $reply = json_decode(trim(stripcslashes($st), '"'), true); echo "\nLets go!\n"; $fee = getKeyFromArray('transaction_fee', $reply); echo "\n++++++++++++++++++++++++++++\n"; print_r($fee); $fee = getFee($st); echo "\n++++++++++++++++++++++++++++\n"; print_r($fee); $fee = getTheFuckingKeyFromTheFuckingArrayWithoutFuckingTroubles('transaction_fee', $reply); echo PHP_EOL, "Why is PHP such a bad language?!", PHP_EOL; echo PHP_EOL, "++++++++++++++++++++++++++++", PHP_EOL; echo PHP_EOL, print_r($fee, 1); function getFee($s) { // we need to locate something like this // "transaction_fee":{"value":"0.89","currency":"USD"} $p = strpos($s, 'transaction_fee'); $max = strlen($s); echo "\nGot p = $p\n"; if ($p > 0) { // scan for '{' to '}' $p1 = $p; while ($s[$p1] != '{' && $p1 < $max) { $p1++; } echo "\nGot p1 = $p1\n"; $p2 = $p1; while ($s[$p2] != '}' && $p2 < $max) { $p2++; } echo "\nGot p2 = $p2\n"; $r = substr($s, $p1, $p2 - $p1).'}'; return @json_decode($r, true); //return $r; } else { echo "WTF2????"; return null; } } function getKeyFromArray($dataItemName, $array) { foreach ($array as $key => $value) { echo "\nChecking ".(string)$key."\n"; if ((string)$key == $dataItemName) { echo "\nGot needle!\n"; return $value; } if (is_array($value)) { echo "\n ".(string)$key." is an array, going deeper.\n"; echo "\n============================\n"; print_r($value); echo "\n============================\n"; return getKeyFromArray($dataItemName, $value); } } echo "\nWTF???\n"; return null; } /** * @param string $theFuckingKey * @param array $theFuckingArray * * @return mixed|null */ function getTheFuckingKeyFromTheFuckingArrayWithoutFuckingTroubles/* please */($theFuckingKey, array $theFuckingArray) { foreach (new \RecursiveIteratorIterator(new \RecursiveArrayIterator($theFuckingArray), RecursiveIteratorIterator::SELF_FIRST) as $key => $value) { if ($key === $theFuckingKey) { return $value; } } return null; }
Output for git.master, git.master_jit, rfc.property-hooks
Lets go! Checking id Checking intent Checking state Checking cart Checking payer payer is an array, going deeper. ============================ Array ( [payment_method] => paypal [status] => VERIFIED [payer_info] => Array ( [email] => user@host.com [first_name] => NAME [middle_name] => XXX [last_name] => LNAME [payer_id] => ZZZZZZZZZZZZZ [country_code] => MD ) ) ============================ Checking payment_method Checking status Checking payer_info payer_info is an array, going deeper. ============================ Array ( [email] => user@host.com [first_name] => NAME [middle_name] => XXX [last_name] => LNAME [payer_id] => ZZZZZZZZZZZZZ [country_code] => MD ) ============================ Checking email Checking first_name Checking middle_name Checking last_name Checking payer_id Checking country_code WTF??? ++++++++++++++++++++++++++++ Got p = 891 Got p1 = 908 Got p2 = 945 ++++++++++++++++++++++++++++ Array ( [value] => 0.89 [currency] => USD ) Why is PHP such a bad language?! ++++++++++++++++++++++++++++ Array ( [value] => 0.89 [currency] => USD )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
103.5 ms | 1722 KiB | 4 Q