note 86316 added to function.array-walk-recursive

From: Date: Mon, 13 Oct 2008 00:41:05 +0000
Subject: note 86316 added to function.array-walk-recursive
Groups: php.notes 
Request: Send a blank email to php-notes+get-145300@lists.php.net to get a copy of this message
Nice system to make DB tree using function array_walk_recursive: function _CategoriesTree(&$item, $key) { global $objDB; if ($key=="childs") { $res = $objDB->getAssoc('SELECT category_id, name,category_parent_id, category_id AS childs FROM categories WHERE category_parent_id = '.$item.' ORDER BY orderid'); if(!empty($res)) { // walk inside subcategories $item = $res; } else { // equvalent => no childs $item = -1; } } } $categories = $objDB->getAssoc('SELECT category_id, name,category_parent_id, category_id AS childs FROM categories WHERE category_parent_id = 0 ORDER BY orderid'); // fetchPairs -> value is the index array_walk_recursive($categories, 'treeFunc',$objDB); // test print_r($categories); ---- Server IP: 80.241.173.254 Probable Submitter: 83.211.184.83 ---- Manual Page -- http://www.php.net/manual/en/function.array-walk-recursive.php Edit -- https://master.php.net/note/edit/86316 Del: integrated -- https://master.php.net/note/delete/86316/integrated Del: useless -- https://master.php.net/note/delete/86316/useless Del: bad code -- https://master.php.net/note/delete/86316/bad+code Del: spam -- https://master.php.net/note/delete/86316/spam Del: non-english -- https://master.php.net/note/delete/86316/non-english Del: in docs -- https://master.php.net/note/delete/86316/in+docs Del: other reasons-- https://master.php.net/note/delete/86316 Reject -- https://master.php.net/note/reject/86316 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#145300) next »