// Given a sorted array of distinct integers and a target value, return the index if the target is found. // If not, return the index where it would be if it were inserted in order.
function searchInsert($nums, $target) {
    if (in_array($target, $nums)) {
        $index = array_search($target, $nums);
	return $index;
    }
    if (!in_array($target, $nums)) {
        array_push($nums, $target);
	sort($nums);
	$index2 = array_search($target, $nums);
	return $index2;
    }
}
echo searchInsert([1, 3, 5, 6], 5);  // 2
echo searchInsert([1, 3, 5, 6], 2);  // 1
by Luka Khitaridze
2 years ago
PHP
Array
0
Pro tip: use ```triple backticks around text``` to write in code fences