3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * This code should loop through $data, converting null to 0. * * If it finds an array inside the data, it loops through that * converting null values to 0. * * The error'ed line throws the following PHP error which breaks the code: * ------- * PHP Warning: Cannot use a scalar value as an array * ------- */ $data = json_decode('{"last":"0.692776960","high":"0.692776960","low":"0.692776960","avg":0.6928,"vol":"0.252273837","vols":{"bid":null,"ask":null}}', 1); $new_data = []; foreach($data as $outer_key=>$outer_value) { var_dump($new_data); if(is_array($outer_value)) { $new_key = (string) $outer_key; // ERROR LINE START $new_data[$new_key] = []; // ERROR LINE END foreach($outer_value as $inner_key=>$inner_value) { Log::info("k is " . json_encode($outer_key) . "v is " . json_encode($outer_value) . " p is " . json_encode($inner_key) . " and z is " . json_encode($inner_value) . ""); $new_data[$new_key][$inner_key] = ($inner_value !== null) ?: 0; } } else { $new_data = ($data !== null) ?: 0; } }
Output for git.master, git.master_jit, rfc.property-hooks
array(0) { } bool(true) bool(true) bool(true) bool(true) bool(true) Fatal error: Uncaught Error: Cannot use a scalar value as an array in /in/VqhU3:20 Stack trace: #0 {main} thrown in /in/VqhU3 on line 20
Process exited with code 255.

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:
41.02 ms | 401 KiB | 8 Q