Find a missing number

Links for php scripts

Moderators: macek, egami, gesf

User avatar
epox123
New php-forum User
New php-forum User
Posts: 77
Joined: Mon Aug 08, 2005 8:44 pm
Location: USA

Find a missing number

Postby epox123 » Tue Feb 14, 2006 9:56 pm

Heheh this was hard to come up with i hope it helps you.
use it freely have fun.

ps: this also works with mysql ;-)


Array:

Code: Select all

<?php
$row = array('0','2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12');
$numrow = count($row) + 1;
for($i = 1; $i <= $numrow; $i++){
$a = $i - 1;
if($row[$a] != $i){
echo 'The missing number is '.$i.'<br />'."\n";
$i = $numrow;
}
}

print_r($row);

?>


MySQL:

Code: Select all

<?php
$x = 0;
while($row1 = mysql_fetch_array($result)){
$row2[$x] = $row1['????'];
$x++;
}
$numrow = count($row2) + 1;
for($i=1; $i<=$numrow; $i++){
$j = $i - 1;
if($row2[$j] != $i){
$tid = $i;
$i = $numrow;
}
}
?>

Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest

cron