![]() |
how to access the count? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: how to access the count? (/showthread.php?tid=71487) Pages:
1
2
|
how to access the count? - richb201 - 08-19-2018 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? RE: how to access the count? - donpwinston - 08-19-2018 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. RE: how to access the count? - richb201 - 08-19-2018 $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 RE: how to access the count? - skunkbad - 08-19-2018 Try $data = $result->getData(); Or $count = $result->getCount(); RE: how to access the count? - richb201 - 08-20-2018 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. RE: how to access the count? - php_rocs - 08-20-2018 @richb201, You could also count the items array. RE: how to access the count? - richb201 - 08-20-2018 (08-20-2018, 10:03 AM)php_rocs Wrote: @richb201, Yes, is there a php function which returns the count of the items (or any) array? RE: how to access the count? - richb201 - 08-20-2018 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..... RE: how to access the count? - richb201 - 08-20-2018 Trial and error works! This worked: $iCount=$result['Count']; RE: how to access the count? - php_rocs - 08-20-2018 @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. |