• Resolved Peter_L

    (@peter_l)


    PHP has the count function, that counts the number of elements in an array.

    I am currently using the WordPress function get_terms. This returns an array with one of the fields inside this array called count. ( http://codex.ww.wp.xz.cn/Function_Reference/get_terms#Return_Values )

    When I loop out this array, using foreach, I get to this line at a certain point:
    $term->count
    This should and does return the number of posts inside the currently looped taxonomy term.

    Here’s my question: will the count in the rule above make the server think, hello php function. I am going to execute you and get an error somehow.

    I don’t know how to say this more clearly. Isn’t count a php reserved term?

Viewing 2 replies - 1 through 2 (of 2 total)
  • vtxyzzy

    (@vtxyzzy)

    I think you have the answer in your question, it is just not obvious.

    PHP has a ‘count’ function. $term->count is a reference to a data item named ‘count’. PHP can have a function and a data item both named the same thing without any conflict.

    Thread Starter Peter_L

    (@peter_l)

    Everything does work just fine, it just got me confused a bit.
    Thanks for answering.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘php function 'count' versus wordpress array field 'count'’ is closed to new replies.