简体   繁体   中英

mysql_num_rows equivalent for JSON in PHP

Can you do a similar test when returning JSON with PHP like mysql_num_rows?

Therefore i can do an IF statement and echo a different piece of text for when there's no JSON available?

Not sure what the context is but you can do

$array = json_decode($json_string);
$num = count($array);

That's if the json_string is an array.

$data = json_decode("some json");
echo count($data);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM