3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A { function __construct() { $this->arr = [1,34,3,98,9,76,45,4]; } function joinNumbers($a, $b) { $t=10; while($b>=$t) $t*=10; return $a*$t+$b; } function arrangeNumbers() { $size=count($this->arr)/count($this->arr[0]); for($i=0;$i<$size-1;$i++) { for($j=$i+1;$j<$size;$j++) { if(joinNumbers($this->arr[$i],$this->arr[$j])<joinNumbers($this->arr[$j],$this->arr[$i])) { $temp = $this->arr[$i]; $this->arr[$i] = $this->arr[$j]; $this->arr[$j] = $this->arr[$i]; } } } printf("Number is : "); for($i=0;$i<$size;$i++) { printf("%d",$this->arr[$i]); } printf("\n\n"); } } $test = new A; $test->arrangeNumbers();
based on GuuYD
Output for 7.2.0
Warning: count(): Parameter must be an array or an object that implements Countable in /in/TbKPt on line 17 Fatal error: Uncaught Error: Call to undefined function joinNumbers() in /in/TbKPt:21 Stack trace: #0 /in/TbKPt(37): A->arrangeNumbers() #1 {main} thrown in /in/TbKPt on line 21
Process exited with code 255.
Output for 7.0.0 - 7.1.10
Fatal error: Uncaught Error: Call to undefined function joinNumbers() in /in/TbKPt:21 Stack trace: #0 /in/TbKPt(37): A->arrangeNumbers() #1 {main} thrown in /in/TbKPt on line 21
Process exited with code 255.
Output for 5.4.11 - 5.6.28
Fatal error: Call to undefined function joinNumbers() in /in/TbKPt on line 21
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/TbKPt on line 4
Process exited with code 255.