note 100472 added to book.array
| From: | subzey at immelman dot ru | Date: | Mon, 18 Oct 2010 14:48:20 +0000 |
| Subject: | note 100472 added to book.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173247@lists.php.net to get a copy of this message | ||
To macnimble at gmail dot com:
It's more convenient (for me) to organize trees using a DOMDocument element.
<?php
$document = new DOMDocument();
$res = pg_query("SELECT id, pid, ⦠FROM ⦠ORDER BY â¦");
while ($line = pg_fetch_assoc($res)){
$element = $document->createElement("element");
$elements_by_id[$line['id']] = array(0 => $element, 1 => $line['pid']);
$element->setAttribute("id", $line['id']);
$element->setAttribute("name", $line['name']);
$element->setAttribute("â¦etcâ¦", $line['â¦etcâ¦']);
};
foreach ($elements_by_id as $element_composition){
list ($element, $pid) = $element_composition;
if (isset($elements_by_id[$pid])){
$elements_by_id[$pid]->appendChild($element);
};
};
?>
Result is the tree of DOMElements, with XPath, useful tree manupulation methods and much more.
Also, it's very extensible: actual code I used was twice that big handling all possible tree
corruption handling and the result was an UL-LI HTML tree just in place. And it also preserves ORDER
BY.
----
Server IP: 195.54.192.44
Probable Submitter: 127.0.0.1
----
Manual Page -- http://www.php.net/manual/en/book.array.php
Edit -- https://master.php.net/note/edit/100472
Del: integrated -- https://master.php.net/note/delete/100472/integrated
Del: useless -- https://master.php.net/note/delete/100472/useless
Del: bad code -- https://master.php.net/note/delete/100472/bad+code
Del: spam -- https://master.php.net/note/delete/100472/spam
Del: non-english -- https://master.php.net/note/delete/100472/non-english
Del: in docs -- https://master.php.net/note/delete/100472/in+docs
Del: other reasons-- https://master.php.net/note/delete/100472
Reject -- https://master.php.net/note/reject/100472
Search -- https://master.php.net/manage/user-notes.php