Skip to content

Is all digits

PHP loop + condition

Flowchart (ISO 5807)

YesNoStartInput si = 0, |s| − 1, 1c = s[i]c < «0» or c > «9»Return falseEndReturn trueEndFigure 1 — allDigits

Source code

PHP
function allDigits($s) {
    for ($i = 0; $i < strlen($s); $i++) {
        $c = $s[$i];
        if ($c < '0' || $c > '9') {
            return false;
        }
    }
    return true;
}

The editor opens with this code — change it and the chart redraws.

Language
PHP
Constructs
loop + condition
Topic
Loops
Formats
Word, Visio, draw.io, PDF, SVG

Related examples