2 回答

TA貢獻1836條經驗 獲得超5個贊
加了offset不加length的話系統會自動取數組中元素的個數來補全,但是不加offset卻加了length則會報錯。
下面大概說一下這里thinkphp是如何實現的:
thinkphp這里是用的數組截取,也就是array_slice函數,
1 2 | array array_slice ( array $array , int $offset [, int $length [, bool $preserve_keys ]] ) |
array_slice() 默認將重置數組的鍵。自 PHP 5.0.2
起,可以通過將 preserve_keys 設為
TRUE 來改變此行為。
這里因為要保存原來的鍵值,所以需要第四個參數TRUE的。
模板和實現對應:
1、正常
1 | <volist name="lists" id="list" offset="0" length='15'> |
1 | $__LIST__ = array_slice($lists,0,15,true); |
2、正常
1 | <volist name="lists" id="list" offset="0"> |
1 | $__LIST__ = array_slice($lists,0,count($__LIST__),true); |
3、報錯
1 | <volist name="lists" id="list" length="15"> |
1 | $__LIST__ = array_slice($lists,,15,true); |
- 2 回答
- 0 關注
- 1432 瀏覽
添加回答
舉報