logo CodeStepByStep logo

is_sorted

Language/Type: PHP arrays sorting traversals

Write a function named is_sorted that accepts an array of numbers as a parameter and returns true if the array is in sorted order and false if not.

For example, if an array named $arr stores [1.5, 4.3, 7.0, 19.5, 25.1, 46.2], the call of is_sorted($arr) should return true. A one-element array is considered to be sorted.

Constraints:

  • You may assume the array has at least one element.
  • Do not modify the array passed in.
Function: Write a PHP function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.