April 2, 2011

How to find whether a json array is empty or not?

Question by hbase_user

How to find whether a json array is empty or not using PHP?
empty($jsonarray) seems doesn’t work!

Answer by Starx

Try this

if(count(json_decode($jsonarray,1))==0) {
    echo "empty";
}

//or
if(empty(json_decode($jsonarray,1))) {
    echo "empty";
}

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!