Kumar Saurabh Sinha
Kumar Saurabh Sinha

Reputation: 870

Issue with count() in php

I have the following code block in my controller

$reportPostCountArray = $this->objUserModel->findDuplicateReportPost($payloadData['user_id'], $payloadData['post_id']);
var_dump($reportPostCountArray);

count($reportPostCountArray);
var_dump(is_array($reportPostCountArray));

and the output for the above code is following:

array(1) {
  [0]=>
  object(stdClass)#179 (1) {
    ["post_count"]=>
    int(1)
  }
}
bool(true)

Please help me to correct why I am not getting the count value even though the return is an array with size 1.

Upvotes: 0

Views: 47

Answers (1)

Adam Sinclair
Adam Sinclair

Reputation: 1649

That is what you want to do:

var_dump($count($reportPostCountArray));

You were not printing the count value with var_dump() but an array and the return value of is_array() which is indeed a boolean, in this case true.

Upvotes: 1

Related Questions