how to access the count? |
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?
proof that an old dog can learn new tricks
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.
Simpler is always better
$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
proof that an old dog can learn new tricks
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.
proof that an old dog can learn new tricks
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.....
proof that an old dog can learn new tricks
Trial and error works!
This worked: $iCount=$result['Count'];
proof that an old dog can learn new tricks
@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. |
Welcome Guest, Not a member yet? Register Sign In |