0

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 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>");
2
  • Are you talking about $berichtenArr? If yes, where is it defined?
    – Donovan
    Mar 28, 2011 at 12:34
  • Where is $berichtenArr being set? Mar 28, 2011 at 12:34

3 Answers 3

0
$amountMess = count($messagesArr);

$berichtenArr != $messagesArr

2
  • ouch i though I had the translation down but in the original the count argument is the same. Still the count function will not do it
    – Immers
    Mar 28, 2011 at 13:12
  • What exactly does not work? Switch on full PHP error reporting and check for notices or warnings. Output a var_dump($messagesArr). Mar 28, 2011 at 15:23
0

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.

0

You need to define $berichtenArr:

$berichtenArr = array(blahhhh, foooo, barrrr);

Otherwise count($berichtenArr) won't return anything useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.