PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php printf("Current PHP version: %s \n", phpversion()); $query = "SELECT VERSION() as version;"; $stmt = $pdo->prepare($query); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); printf('DB version: %s', $row['version']); $arr = [1, 10, 5, 2, 13, 9, 7, 12, 6, 20, 3, 8]; sort($arr); echo "\n\n"; function search($arr, $val) { if (empty($arr)) { return false; } $low = 0; $high = count($arr) - 1; while ($low <= $high) { // compute middle index $mid = floor(($low + $high) / 2); // element found at mid if($arr[$mid] == $val) { return true; } if ($val < $arr[$mid]) { // search the left side of the array $high = $mid - 1; } else { // search the right side of the array $low = $mid + 1; } } // If we reach here element x doesnt exist return false; } $value = 20; $found = search($arr, $value); if ($found === false) { echo "Value $value was NOT found."; } else { echo "Value $value exists."; }
Show:  
Copy Clear