w3resource

PHP function Exercises: Checks whether a string is all lower case

PHP function: Exercise-5 with Solution

Write a PHP function that checks whether a string is all lower case.

Pictorial Presentation:

PHP function Exercises: Checks whether a string is all lower case

Sample Solution:

PHP Code:

<?php
function is_str_lowercase($str1)
   {
    for ($sc = 0; $sc < strlen($str1); $sc++) {
	      if (ord($str1[$sc]) >= ord('A') &&
          ord($str1[$sc]) <= ord('Z')) {
      return false;
         }
         }
      return true;
       }
var_dump(is_str_lowercase('abc def ghi'));
var_dump(is_str_lowercase('abc dEf ghi'));
?>

Sample Output:

bool(true)                                                  
bool(false)

Flowchart :

Flowchart: Checks whether a string is all lower case

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a function to sort an array.
Next: Write a PHP function that checks whether a passed string is a palindrome or not?

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Share this Tutorial / Exercise on : Facebook and Twitter

PHP: Tips of the Day

Formatting a number with leading zeros in PHP

Use sprintf :

sprintf('%08d', 1234567);

Alternatively you can also use str_pad:

str_pad($value, 8, '0', STR_PAD_LEFT);

Ref : https://bit.ly/3fS2OLd