Model a command-line option that carries a numeric value.

option-value Some options are pairs: an option name and the value that follows it. The script can validate the value before using it.

Option Values

limit
option_value.php
Replay: real traced execution (multi-file project)
<?php
$limit = 10;
$option = "--limit";
$accepted = $limit >= 1 && $limit <= 20;
$status = $accepted ? "accepted" : "rejected";

echo "option=" . $option . "\n";
echo "limit=" . $limit . "\n";
echo "status=" . $status . "\n";
<?php
$limit = 5;
$option = "--limit";
$accepted = $limit >= 1 && $limit <= 20;
$status = $accepted ? "accepted" : "rejected";

echo "option=" . $option . "\n";
echo "limit=" . $limit . "\n";
echo "status=" . $status . "\n";
<?php
$limit = 20;
$option = "--limit";
$accepted = $limit >= 1 && $limit <= 20;
$status = $accepted ? "accepted" : "rejected";

echo "option=" . $option . "\n";
echo "limit=" . $limit . "\n";
echo "status=" . $status . "\n";
  1. $limit ← 10, $option ← --limit, $accepted ← 1, $status ← accepted

    1<?php2$limit→ 10 = 10; //@limit=5, 203$option→ --limit = "--limit";4$accepted→ 1 = $limit10 >= 1 && $limit <= 20;5$status→ accepted = $accepted1 ? "accepted" : "rejected";67echo "option=" . $option--limit . "\n";8echo "limit=" . $limit10 . "\n";9echo "status=" . $statusaccepted . "\n";
    outputoption=--limit
    limit=10
    status=accepted
  1. $limit ← 5, $option ← --limit, $accepted ← 1, $status ← accepted

    1<?php2$limit→ 5 = 5;3$option→ --limit = "--limit";4$accepted→ 1 = $limit5 >= 1 && $limit <= 20;5$status→ accepted = $accepted1 ? "accepted" : "rejected";67echo "option=" . $option--limit . "\n";8echo "limit=" . $limit5 . "\n";9echo "status=" . $statusaccepted . "\n";
    outputoption=--limit
    limit=5
    status=accepted
  1. $limit ← 20, $option ← --limit, $accepted ← 1, $status ← accepted

    1<?php2$limit→ 20 = 20;3$option→ --limit = "--limit";4$accepted→ 1 = $limit20 >= 1 && $limit <= 20;5$status→ accepted = $accepted1 ? "accepted" : "rejected";67echo "option=" . $option--limit . "\n";8echo "limit=" . $limit20 . "\n";9echo "status=" . $statusaccepted . "\n";
    outputoption=--limit
    limit=20
    status=accepted