Elsasser
Elsasser

Reputation: 11

Function Count ($array)

The answer is probably obvious for many of you, but : how can I make the function "count" work proprerly ? Here four lines of my program :

$liste=array($serie); 
if (is_array($liste))  {
    echo "Dans la proc., Liste est toujours un tableau<br>";
} 
echo "Nb de lignes de la liste : " . count($liste)."<br>";

The answer to my if is true, but count is 1 - actually 1163 elements !

Upvotes: 1

Views: 50

Answers (1)

Ranjit Shinde
Ranjit Shinde

Reputation: 1130

$liste=array($serie); this code creating an new array that's why its count is 1. assign it directly as below

$liste = $serie; 
if (is_array($liste))  {
    echo "Dans la proc., Liste est toujours un tableau<br>";
} 
echo "Nb de lignes de la liste : " . count($liste)."<br>";

I recommend to echo your count() inside the if statement.

Upvotes: 1

Related Questions