Skip to content

Instantly share code, notes, and snippets.

@4RSIM3R
Last active October 12, 2023 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4RSIM3R/ad304eedeb496a436cb2b924555bc255 to your computer and use it in GitHub Desktop.
Save 4RSIM3R/ad304eedeb496a436cb2b924555bc255 to your computer and use it in GitHub Desktop.
<?php
// di berikan sebuah angka, cari posisi index angka tersebut dalam array
// input : arr = [1, 2, 3, 4, 5], i = 3
// output : 2
// input : arr = [1, 2, 3, 4, 5], i = 9
// output : -1
function findMe($arr, $i)
{
return -1;
}
$arr = [1, 2, 3, 4, 5];
$result = findMe($arr, 3);
echo json_encode($result); // 2
echo "<br />";
$arr = [1, 2, 3, 4, 5];
$result = findMe($arr, 9);
echo json_encode($result); // -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment