The difference between $ arrayname [item] value and $ arrayname [item] value when reading the wordpress taxonomy. php source code, an array creation problem occurs. in summary:
$ Arrayname [item] = What is the difference between value and $ arrayname [item] [] = value? In this example, the number/value is switched to the next position, right? Please kindly advise.
In function _ get_term_hierarchy ($ taxonomy:
$ Children = array ();
$ Terms = get_terms ($ taxonomy, array ('get' => 'all', 'orderby' => 'id ', 'fields' => 'Id => parent '));
Foreach ($ terms as $ term_id => $ parent ){
If ($ parent> 0)
$ Children [$ parent] [] = $ term_id;
}
In function get_terms ($ taxonomies, $ args =:
$ _ Terms = array ();
If ('Id => parent' ==$ _ fields ){
Foreach ($ terms as $ term ){
$ _ Terms [$ term-> term_id] = $ term-> parent;
}
}
Reply to discussion (solution)
First, you [] do not use quotation marks to enclose Variables. otherwise ..... $ arrayname [item] = value this is a one-dimensional array. The value of the element whose $ arrayname is set to 'item' is value and $ arrayname ['item'] [] = value is two-dimensional. array sets the value of the current position of the lower-level array of array $ arrayname ['item'] to value
$ Children [$ parent] []
$ Children [$ parent] = it may be an array (there may be many sub-items, but it may be an array)
$ _ Terms [$ term-> term_id] = $ term-> parent;
$ _ Terms [$ term-> term_id] = can only be one value (only one parent item can be)
Yes
$ _ Terms [$ term-> term_id] = $ term-> parent;
The parent node used to collect each term_id (term_id is unique)
$ Children [$ parent] [] = $ term_id;
Used to cluster subnodes
The former is a direct value assignment.
The latter creates an array and then adds the last element.
The former is a direct value assignment.
The latter creates an array and then adds the last element.
-- 'Create an array and add the last element? I don't understand.
$ _ Terms [$ term-> term_id] = $ term-> parent;
The parent node used to collect each term_id (term_id is unique)
$ Children [$ parent] [] = $ term_id;
Used to cluster subnodes
---- Understandable
$ Arrayname [item] = value and $ arrayname [item] [] = value are constructed into an array like this, right?
$ Aaa = array (
3 => 7,
6 => 9)
$ Bbb = array (
3 => array (
0 => 8,
1 => 4,
)
)
The latter creates an array and then adds the last element.
-- 'Create an array and add the last element? I don't understand.
For
Foreach ($ terms as $ term ){
$ _ Terms [$ term-> term_id] = $ term-> parent;
}
The value assignment is executed in a loop.
If $ term-> term_id is not unique, that is, $ term-> term_id appears repeatedly.
Then, $ _ terms [$ term-> term_id] is the last $ term-> parent of the same $ term-> term_id.