在php中获取循环的总数

Can somebody help i'm trying get the total of loop.

Heres my code

echo '<form name="fproduct" action="product.php" method="post"> 
<br/><textarea name="item" rows="10" cols="20"></textarea> <br/>
<input type="submit" value="Submit" />
</form>';

if(isset($_POST['item'])) {
    $j = 0;
    $arry=explode( "\\
", $_POST['item'] );
    for ($i = 0; $i <= count($arry); $i++) {
        if((trim($arry[$i])) != null) {
            $j++;
        }
    }
    Print $j;
}

Whats wrong with this.

Try to use alone instead.

if(isset($_POST['item'])){
    $j = 0;
    $arry=explode( "
", $_POST['item'] );
    for ($i = 0; $i < count($arry); $i++) 
    {
        if((trim($arry[$i]))!= null){
            $j++;
        }
    }
    echo $j;
}

I suggest use foreach:

if(isset($_POST['item'])){
    $count = 0;
    $item = explode("
", $_POST['item']);
    foreach($item as $line) {
        if(trim($line) != '') $count++;
    }
    echo $count;
}