Getting Facebook comments count via FQL
Please use braces {} to wrap your code, even those one line if statements, makes it so much easier to read.

First off, you do know that JSON has an option to output an array right? json_decode( $json, TRUE ) returns an array. No need to create a function for it.

"there's no native PHP function for that" - If it uses the countable interface, which is any data object I've come across (XML, JSON, SQL, etc...) then you can just use count(). If you have an object that holds the comments I would just try using count() on that first before creating a new query just to get a count.

Make sure you are not calling the "same" object twice. I imagine you can just get the whole table into an array then perform array operations on it to get the desired results without having to query the server multiple times. This is probably the biggest reason your program runs so slow. Hope this helps!