3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php echo convert_fraction_to_decimal('3 1/16'); function convert_fraction_to_decimal( $fraction_string){ $fraction_string_array = explode( ' ', $fraction_string); $whole_number = $fraction_string_array[0]; $fraction_number = $fraction_string_array[1]; $fraction_decimal = 0; if( $fraction_number != 0){ $fraction_number_array = explode($fraction_number, '/'); $fraction_decimal = $fraction_number_array[0] / $fraction_number_array[1]; } $return_number = $fraction_number + $fraction_decimal; return $return_number; }
based on S6sFM
Output for 7.1.0
Notice: Undefined offset: 1 in /in/G14Ha on line 12 Warning: A non-numeric value encountered in /in/G14Ha on line 12 Warning: Division by zero in /in/G14Ha on line 12 Notice: A non well formed numeric value encountered in /in/G14Ha on line 14 NAN
Output for 7.0.0 - 7.0.14
Notice: Undefined offset: 1 in /in/G14Ha on line 12 Warning: Division by zero in /in/G14Ha on line 12 NAN
Output for 5.3.0 - 5.6.21
Notice: Undefined offset: 1 in /in/G14Ha on line 12 Warning: Division by zero in /in/G14Ha on line 12 1
Output for 4.3.0 - 5.2.17
Notice: Undefined offset: 1 in /in/G14Ha on line 12 Warning: Division by zero in /in/G14Ha on line 12 1