3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * An array in DESCENDING order (OP) */ $array = [ 61029, 64698, 67355, 70000, // has bubble 43651, 48346, 52029, // has bubble 48029, 48698, 49355, 50000, ]; /** * An array in ASCENDING order */ $asc_array = [ 10, 20, 30, 40, 50, 45, //Has bubble 55 ]; /** * Given an array, identify a "bubble", aka. an increasing value in an otherwise decreasing value array. * Returns the $key where the bubble resides. */ function identifyBubble($array){ foreach($array as $id => $item){ if(!$id){ continue; } if(!$array[$id+1]){ continue; } if(($array[$id-1] < $array[$id]) && ($array[$id] > $array[$id+1])){ return $id; } } return false; } /** * If an array is in ASCENDING order, switch it around, * otherwise return the array as is. */ function makeArrayDescending($array){ if(reset($array) < end($array)){ return array_values(array_reverse($array)); } return $array; } var_dump(identifyBubble($array)); var_dump(makeArrayDescending($asc_array)); var_dump(identifyBubble(makeArrayDescending($asc_array)));
Output for git.master, git.master_jit, rfc.property-hooks
int(3) array(7) { [0]=> int(55) [1]=> int(45) [2]=> int(50) [3]=> int(40) [4]=> int(30) [5]=> int(20) [6]=> int(10) } int(2)

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