 Hello,

array(0,1,5,6)

source: 2

How Can I find the grand value than 2 in array (echo 5)

AND

array(1,2,4)

source: 5

If there isn’t a value grand than 5, the output can be 1(on the beginnest). How can I find it?

Thank you

In your first example there are two numbers greater than 2: 5 and 6. Why 5? Because it is the lowest number greater than 2 or because it is encountered first in the list?

Yes, I meant it. first largest number than 2. If there isn’t any largest number than given number, the output can be first number of list.

You can do something like this…

[php]\$numbers = array (0,1,5,6);
\$count = count(\$numbers);
\$source = 2;
\$found = false;

for (\$i = 0; \$i < \$count; \$i++) {
if (\$source > \$numbers[\$i]) {
echo \$numbers[\$i];
\$found = true;
break;
}

if (\$found === false) {
echo \$numbers;
}
[/php]

[php]\$numbers = array (1,2,4);
\$count = count(\$numbers);
\$source = 5;
\$found = false;

for (\$i = 0; \$i < \$count; \$i++) {
if (\$source > \$numbers[\$i]) {
echo \$numbers[\$i];
\$found = true;
break;
}

if (\$found === false) {
echo \$numbers;
}
[/php]

Thanks so much. God bless your hands.
I can’t run it. Where did I do a mistake?

[php]
\$numbers = array (0,1,5,6);
\$count = count(\$numbers);
\$source = 2;
\$found = false;

``````for (\$i = 0; \$i < \$count; \$i++) {
if (\$source > \$numbers[\$i]) {
echo \$numbers[\$i];
\$found  = true;
break;
``````

}
} // This “}” was missing
if (\$found === false) {
echo \$numbers;
}
[/php]

I think Topcoder’s will only work if the array is already sorted. Try:

[php]\$numbers = array (0,1,5,6);
sort(\$numbers);
\$source = 2;
\$result = \$numbers;

foreach(\$numbers as \$number) {
if(\$number > \$source) {
\$result = \$number;
break;
}
}[/php]

@AbraCadaver You’re amazing, thanks for pointing that…

Each of you, thank you very very very very very much
Am trying for this script, http://www.zamanlayici.antenfiyati.com

Again thank you