Created
October 5, 2017 15:31
-
-
Save AnrDaemon/68e7f1372e0a28d88d2490aacfff3a9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$list = $_pdo->getAll('SELECT s1.`id` `id` FROM cat_section s1 | |
LEFT JOIN cat_section s2 ON s1.`parent_id` = s2.`id` | |
WHERE s1.`parent_id` <> 0 AND s2.`id` IS NULL', [], \PDO::FETCH_COLUMN); | |
$iter = function($sid) | |
use(&$iter, $_pdo) | |
{ | |
foreach($_pdo->getAll('SELECT s1.`id` `id` FROM cat_section s1 | |
WHERE s1.`parent_id` = ?', [$sid], \PDO::FETCH_COLUMN) as $id | |
) | |
{ | |
yield $id; | |
foreach($iter($id) as $cid) | |
{ | |
yield $cid; | |
} | |
} | |
}; | |
$data = $list; | |
foreach($list as $sid) | |
{ | |
foreach($iter($sid) as $id) | |
{ | |
$data[] = $id; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment