3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $state_id = ''; $zone_id = ''; $postcode = ''; $postcode_required = ''; function validate($state_id,$zone_id,$postcode,$postcode_required) { $message = array( 'warning' => 'Warning: No Shipping options are available. Please contact us for assistance!', 'state' => 'Please select a state!', 'zone' => 'Please select a city / area!', 'postcode' => 'Postcode must be between 4 and 10 characters!' ); $delivery_quites = array('state' => $state_id, 'zone' =>$zone_id, 'postcode'=>$postcode, 'postcode_required'=>$postcode_required ); $data = ''; foreach($delivery_quites as $key => $value){ if ($value['state'] =''){ $data['state'] = $message[$key]; } if ($value['zone'] =''){ $data['zone'] = $message['zone']; } } return $data; } $test = validate($state_id,$zone_id,$postcode,$postcode_required); print_r(json_encode(array('error' => $test))); //print_r($delivery_quites); ?>
Output for 7.1.0
Warning: Illegal string offset 'state' in /in/hEnTj on line 22 Warning: Cannot assign an empty string to a string offset in /in/hEnTj on line 22 Warning: Illegal string offset 'zone' in /in/hEnTj on line 25 Warning: Cannot assign an empty string to a string offset in /in/hEnTj on line 25 Warning: Illegal string offset 'state' in /in/hEnTj on line 22 Warning: Cannot assign an empty string to a string offset in /in/hEnTj on line 22 Warning: Illegal string offset 'zone' in /in/hEnTj on line 25 Warning: Cannot assign an empty string to a string offset in /in/hEnTj on line 25 Warning: Illegal string offset 'state' in /in/hEnTj on line 22 Warning: Cannot assign an empty string to a string offset in /in/hEnTj on line 22 Warning: Illegal string offset 'zone' in /in/hEnTj on line 25 Warning: Cannot assign an empty string to a string offset in /in/hEnTj on line 25 Warning: Illegal string offset 'state' in /in/hEnTj on line 22 Warning: Cannot assign an empty string to a string offset in /in/hEnTj on line 22 Warning: Illegal string offset 'zone' in /in/hEnTj on line 25 Warning: Cannot assign an empty string to a string offset in /in/hEnTj on line 25 {"error":""}
Output for 5.2.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.0.14
{"error":""}
Output for 5.0.0 - 5.1.6
Fatal error: Call to undefined function json_encode() in /in/hEnTj on line 36
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: json_encode() in /in/hEnTj on line 36
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: json_encode() in /in/hEnTj on line 36
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: json_encode() in /in/hEnTj on line 36