PHP: Indexed Arrays III

Derek Bridge

Department of Computer Science,
University College Cork

PHP: Indexed Arrays III

Aims:

Another built-in function

Class exercises

  1. Given a value $val, write some PHP which echoes 'Yes' if $val is in an array called $a, and 'No' otherwise (using == to test for equality)
  2. Write some PHP to find and echo the smallest number in the array of integers called $a
  3. Write some PHP to find and echo the largest number in the array of positive integers called $a

A remark

In fact, there are built-in functions for each of the above, so we didn't need to write our own PHP:

  1. in_array( $val, $array )
  2. min( $array )
  3. max( $array )