如何调用数组中的Last记录

时间:2013-01-29 04:04:13

标签: php pdf-generation tcpdf

我这样做了吗?我正在尝试调用数组中的最后一个元素:$initr

我的IF语句需要具体询问数组中的每个元素是否是最后一条记录。如果结果是真的,它将在该位置打印条形码。 (IF条件之后的所有内容,你都可以忽略)。

<?php
$initr = $this->record;
$last = end($initr); // Put something like this at the top...

// Then something like this for each record. (I don't know if this is correct syntax)...
if     ($initr[4] == $last) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', .24, '1.58', '', 0.15, 0.015, $barstyle, '');}
elseif ($initr[5] == $last) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 3, '1.58', '', 0.15, 0.015, $barstyle, '');}
elseif ($initr[6] == $last) {$content=$view->pdf->write1DBarcode('01234567094987654321-'.str_replace("-","",$content), 'IMB', 3, '1.58', '', 0.15, 0.015, $barstyle, '');}
?>

1 个答案:

答案 0 :(得分:1)

如果要访问数组中的最后一个元素,可以使用end()

end — Set the internal pointer of an array to its last element

Manual

这是一个例子

$myLastElement = end($initr);