Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Less than (<)

Check a list index against its element count. With zero-based indexing an index equal to the length is already past the last element.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

$left < $right

Check a list index against its element count. With zero-based indexing an index equal to the length is already past the last element.

For numbers the result indicates whether a threshold condition holds. Test the value exactly at the boundary separately. Two numeric strings are compared numerically even when their lengths differ.

  • 7 < 8 → true
  • 8 < 8 → false
  • "12" < "9" → false

Examples

<?php
echo json_encode(7 < 8), PHP_EOL;
echo json_encode(8 < 8), PHP_EOL;
echo json_encode("12" < "9"), PHP_EOL;

Result

true
false
false

Sources