CodeIgniter Forums

Full Version: how to access the count?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I have a $result being returned from a sdk call. It has this structure:
   >data {array} [4]

I am trying to get the Count programmatically (I can see it is 12 in the debugger)


I have tried these plus quite a few others. How can I get $i to equal the the Count?
why not execute a print_r($result)?

if $result is an object then $i = $result->data['Count']

assuming 'Count' references an item in $data and $data is an array.
$result = $dynamodb->query($params);
$iCount = $result->data['Count'];

I am getting an error:

Message: Cannot access private property Aws\Result::$data

Filename: controllers/Configure.php

$data = $result->getData();


$count = $result->getCount();
Those two functions don't exist. I can see the count in the result. I can't seem to take a snapshot of the debug window. here is what I see


Can I somehow get the size of the items array? that would do it.

You could also count the items array.
(08-20-2018, 10:03 AM)php_rocs Wrote: [ -> ]@richb201,

You could also count the items array.

Yes, is there a php function which returns the count of the items (or any) array?
I tried this but it fails:



I then tried


and $iCount = 1 instead of 12

I then tried $iCount=count($result['data'].Items);

and $iCount is 1 instead of 12.

Talk about trial and error.....
Trial and error works!

This worked:


for items it would be...

$iCount = count($result['Items']);

P.S. Your understanding of how arrays work was the challenge in this situation. I had to work on this issue too. I use to hate working with arrays but once I got the hang of it (more practice) I started to love working with arrays. I'm glad you figured it out.
Pages: 1 2