开发者

mysql_num_rows equivalent for JSON in PHP

开发者 https://www.devze.com 2023-02-04 15:38 出处:网络
Can you do a similar test when returning JSON with PHP like mysql_num_rows? Therefore i can do an IF stat开发者_JAVA技巧ement and echo a different piece of text for when there\'s no JSON available?$d

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

Therefore i can do an IF stat开发者_JAVA技巧ement and echo a different piece of text for when there's no JSON available?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消