Checking the Length of Strings and Arrays in PHP
Let we have a variable $str
,
in which some arbitrary string is stored:
<?php
$str = '12345';
?>
Let's write a condition that will display a message on the screen if the length of the string is equal to or greater than three characters:
<?php
$str = '12345';
if (strlen($str) >= 3) {
echo '!';
}
?>
The variable $arr
contains some
array with numbers. Write a condition that
will check that the array has 3
elements.
If so, display the sum of the array's elements
on the screen.