Reputation: 1
I am trying to convert my JSON data to an array & then display the count of records from tje JSON data.
I have decoded the JSON data, but I can't get a count of the records. The data:
Array
(
[http://apps.facebook.com/moviecornpopcorn/index.php/ratemovie/comments?movieid=513] => Array
(
[data] => Array
(
[0] => Array
(
[id] => 10150301107681248_18650149
[from] => Array
(
[name] => Padma Priya
[id] => 100002640672777
)
[message] => nice
[created_time] => 2011-09-12T13:43:39+0000
)
[1] => Array
(
[id] => 10150301107681248_18687009
[from] => Array
(
[name] => Rozyfor Kris
[id] => 100000565855467
)
[message] => good movie
[created_time] => 2011-09-14T10:22:01+0000
[comments] => Array
(
[data] => Array
(
[0] => Array
(
[id] => 10150312170016248
[from] => Array
(
[name] => Rozyfor Kris
[id] => 100000565855467
)
[message] => yes
[created_time] => 2011-09-14T12:17:47+0000
)
[1] => Array
(
[id] => 10150312174296248
[from] => Array
(
[name] => Padma Priya
[id] => 100002640672777
)
[message] => Rozyfor Kris yes
[created_time] => 2011-09-14T12:22:56+0000
)
)
[count] => 2
)
[likes] => 1
)
[2] => Array
(
[id] => 10150301107681248_18687545
[from] => Array
(
[name] => Padma Priya
[id] => 100002640672777
)
[message] => tests
[created_time] => 2011-09-14T11:13:30+0000
)
[3] => Array
(
[id] => 10150301107681248_18688752
[from] => Array
(
[name] => Sravanthi Pasaragonda
[id] => 100001798938835
)
[message] => good moviegood movie.
[created_time] => 2011-09-14T12:56:24+0000
)
[4] => Array
(
[id] => 10150301107681248_18705933
[from] => Array
(
[name] => Sravanthi Pasaragonda
[id] => 100001798938835
)
[message] => kagal looking cool.
[created_time] => 2011-09-15T06:10:33+0000
)
[5] => Array
(
[id] => 10150301107681248_18707928
[from] => Array
(
[name] => Sushma Murali
[id] => 100002207093918
)
[message] => test
[created_time] => 2011-09-15T10:23:00+0000
)
[6] => Array
(
[id] => 10150301107681248_18856609
[from] => Array
(
[name] => Padma Priya
[id] => 100002640672777
)
[message] => NIce movie
[created_time] => 2011-09-23T13:42:42+0000
[likes] => 1
)
[7] => Array
(
[id] => 10150301107681248_18856718
[from] => Array
(
[name] => Padma Priya
[id] => 100002640672777
)
[message] => good
[created_time] => 2011-09-23T13:50:36+0000
)
[8] => Array
(
[id] => 10150301107681248_18939810
[from] => Array
(
[name] => Padma Priya
[id] => 100002640672777
)
[message] => wowww
[created_time] => 2011-09-28T08:15:06+0000
)
[9] => Array
(
[id] => 10150301107681248_18957751
[from] => Array
(
[name] => Padma Priya
[id] => 100002640672777
)
[message] => hiiii
[created_time] => 2011-09-29T05:49:35+0000
)
[10] => Array
(
[id] => 10150301107681248_18990995
[from] => Array
(
[name] => Padma Priya
[id] => 100002640672777
)
[message] => hello
[created_time] => 2011-10-01T04:37:22+0000
)
[11] => Array
(
[id] => 10150301107681248_19022504
[from] => Array
(
[name] => Padma Priya
[id] => 100002640672777
)
[message] => testttt
[created_time] => 2011-10-03T08:12:04+0000
)
)
)
)
Upvotes: 0
Views: 667
Reputation: 198206
You can get the count of any array by using the count
function.
You can access any sub-array by using it's array keys.
$records = $array['http://apps.facebook.com/moviecornpopcorn/index.php/ratemovie/comments?movieid=513']['data'];
$count = count($records);
See as well: Count elements in adjacent array
Upvotes: 1
Reputation: 12750
pretty nasty array key you have there :) so get the current element (with url as array key) values and count the values of it
<?php $data = current($yourarray); $dataCount = count($data); ?>
Upvotes: 0