How can I obtain the Subid function under multiple parent IDs? I am working on a project. I need multiple parent IDs to query the record of the Face ID under the project. I have written a function that can only query the records under a single parent ID. I don't know how to write these records, no idea. could you help me? thank you! Here are my own functions:
function get_child_id($data, $parent_id = '0') { static $child; foreach ($data as $value) { if ($value['parent_id'] == $parent_id) { $child .= ',' . $value['cat_id']; $this->get_child_id($data, $value['cat_id'], $level + 1); } } return $child; }
Reply to discussion (solution)
You can call this method cyclically.
$parent_ids = array(1,2,3,4);$resul t= array();foreach($parent_ids as $parent_id){ $result[] = get_child_id($data, $parent_id);}function get_child_id($data, $parent_id = '0') { static $child; foreach ($data as $value) { if ($value['parent_id'] == $parent_id) { $child .= ',' . $value['cat_id']; $this->get_child_id($data, $value['cat_id'], $level + 1); } } return $child; }
Can I call get_child_id for each parent ID?
However, static $ child; will cause problems in multiple calls
Multiple cycles get_child_id will repeat the subtopic ID
#2 I already told you that something went wrong
The crux is static $ child ;!
function get_child_id($data, $parent_id = '0') { $child = ''; foreach ($data as $value) { if ($value['parent_id'] == $parent_id) { $child .= ',' . $value['cat_id']; $child .= $this->get_child_id($data, $value['cat_id'], $level + 1); } } return $child; }
I found this, but there will still be repeated subtopic IDs.
Paste your test data. the id is not unique (no endless loop is good for you)
Paste your test data. the id is not unique (no endless loop is good for you)
Paste your test data. the id is not unique (no endless loop is good for you)
That's the static problem. too many pages are opened and debugging is wrong. sorry, moderator!
I #4 didn't I give you the code?
I #4 didn't I give you the code?
Now, debugging is complete. Thank you moderator