why is the count($array) function not counting?
I checked if the variable is an array.
I can return desired elements out of the array by going $array[n]
;
so that's all good.
but in the following code I don't get the amount of elements returned if I go count($array)
. sizeof($array)
won't do the job 开发者_StackOverflow中文版either.
//converting string $messages to array:
$messagesArr = explode("<hr/>", $messages);
if (is_array($messagesArr )){print("<p style='color:red'>Array OK<p>");}
else {print("<p style='color:red'>Array not OK<p>");}
$secondElement = $messagesArr[1];
print("<p style='color:red'>second element is: $tweedeElem<p>");
// This one actually outputs the desired second element of the array
$amountMess = count($messagesArr);
print("<p style='color:red'>the amount of messages is: $amountMess<p>");
$amountMess = count($messagesArr);
$berichtenArr
!= $messagesArr
In the code that you've pasted, you're storing the messages in $messagesArr
but calling count on another variable $berichtenArr
. What does that variable contain? Seems you have a bug.
You need to define $berichtenArr
:
$berichtenArr = array(blahhhh, foooo, barrrr);
Otherwise count($berichtenArr)
won't return anything useful.
精彩评论