×

php · level 1 · unit 6 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Ask an array for its biggest, smallest and total.

hands back the biggest item in an array and the smallest. array_sum adds every item up, so a total does not always need a loop.

checks whether a value is in the array. Put the value first, then the array: in_array(19, $temps). It gives true or false, so it fits straight into an if.

To find the first item that matches a question, loop with foreach, check each item with an if, and break as soon as you find it.

<?php
$temps = [14, 19, 11, 17];
echo "Hottest: " . max($temps) . "\n";
echo "Coldest: " . min($temps) . "\n";
echo "All added up: " . array_sum($temps) . "\n";
if (in_array(19, $temps)) {
    echo "We had a 19 degree day!\n";
}

in_array looks for an exact match, so "Dog" with a capital D will not find "dog".