Q:

Write a PHP program to check if the value of each element is equal or greater than the value of previous element of a given array of integers

0

Write a PHP program to check if the value of each element is equal or greater than the value of previous element of a given array of integers

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
function test($numbers)
    { 
       for ($i = 0; $i < sizeof($numbers) - 1; $i++)
          {
             if ($numbers[$i + 1] < $numbers[$i]) 
             return false;
          }
        return true;
    }  
    
var_dump(test([5, 5, 1, 5, 5]));
var_dump(test([1, 2, 3, 4]));
var_dump(test([3, 3, 5, 5, 5, 5]));
var_dump(test([1, 5, 5, 7, 8, 10]));

Sample Output:

bool(false)
bool(true)
bool(true)
bool(true)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now