function find_first_and_Last_position($arr, $n, &$first, &$last) {
for ( $i = 0; $i < count($arr); $i++) {
if ($n != $arr[$i])
continue;
if ($first == -1)
$first = $i;
$last = $i;
}
}
$arr = array(1, 3, 7, 8, 3, 1, 9);
$n = 3;
$first = -1;
$last = -1;
find_first_and_Last_position($arr, $n, $first, $last);
if ($first != -1)
echo "First positions = " . $first . " Last positions = " . $last;
else
echo "Not Found";
/*
run:
First positions = 1 Last positions = 4
*/