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:
$result
   >data {array} [4]
       >Items
         Count
         ScannedCount
      >@metaData

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

$i=$result.data['Count'];
$i=$result->data->Count;

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
Try

$data = $result->getData();

Or

$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

$result={Aws\result}[1]
data={array}[4]
Items{array}[12]
Count=12

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

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:

$iCount=count($result->data.Items);

$iCount=0

I then tried

$iCount=count($result[data].Items);

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:

$iCount=$result['Count'];
@richb201,

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