PHP count JSON array

前端 未结 4 1657
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 15:14

I have searched SO but couldn\'t find an answer.My PHP script is receiving some JSON by http post that looks like this:

{
\"task\": [
{
  \"task_id\": \"3\",         


        
4条回答
  •  离开以前
    2020-12-10 15:48

    Try echo count($task_array['task']);

    In general, if you wonder what the structure of the value of a variable $var is, do a

    Advantage of this function over alternatives such as serialize and print_r is, that it prints PHP code (and is thus readable by anyone who understands PHP (which is likely if you program in PHP)). Disadvantage of var_export is, that it cannot handle circular structures (e.g. if $a->b == $a), but neither can JSON.

提交回复
热议问题