<style>
body, p, li {
font-family: "Arial", "MingLiU"
}
h1, h2, h3, h4, h5, h6 {
font-family: "Arial", "Microsoft YaHei"
}
pre, code {
font-family: "MingLiU";
white-space: pre-wrap !important;
word-break: break-all !important
}
.markdown-body pre {
margin-bottom: 3px;
padding: 10px 12px 6px 12px
}
.markdown-body h6 code {
font-size: 9pt;
font-family: 'Arial';
font-weight: normal;
}
pre.inline {
display: inline;
padding: 0.2em 0;
margin: 0;
line-height: 1.5
}
pre.inline::before, pre.inline::after {
content: "";
display: inline-block;
width: 0.3em
}
</style>
# 表驅動法中的階梯訪問:PHP 參考範例
###### Tags: `Table-driven Methods` `Stair-step Access` `PHP`
表驅動法(Table-driven Methods)階梯訪問(Stair-step Access)的一個簡單的 PHP 範例。
```php
<?php
$x = 13;
$numberNodes = [ 1, 5, 10, 16, 21 ];
$numberTable = [ '0', '1', '2', '3', '4', '5' ];
$numberLevel = 0;
while ($numberLevel < 5)
{
if ($x >= $numberNodes[$numberLevel])
{
++$numberLevel;
continue;
}
break;
}
echo $numberTable[$numberLevel]; // 3
```