I need to create a function in PHP that generates a loop inside the other only that I have not set the loop either (ie infinite), pq and a pyramid-type system, eg: I have 1 dependent that have 4 dependent that per you have 8 depending on you have 2 more dependent And so on, until you reach the end and need to assemble this whole hierarchy or family.
And each dependent upon having dependent, he is dependent but has his own story from the point where he is not pending, to be clearer:
Meu Pai teve 5 filhos.
desses 5 filhos 1 teve 3 filhos.
e Desses 3 filhos veio mais 4 filhos.
And so it goes, understood? everyone can have as many children as they need.
And this data must be in a Mysql table of preference.
Wordpress has 2 tables to do this, I think I understood the process, but I can not see a logic to solve the question:
Table1:
CREATE TABLE 'wp_terms' (
'term_id' bigint(20) UNSIGNED NOT NULL,
'name' varchar(200) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
'slug' varchar(200) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
'term_group' bigint(10) NOT NULL DEFAULT '0'
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
INSERT INTO 'wp_terms' ('term_id', 'name', 'slug', 'term_group') VALUES
(1, 'Sem categoria', 'sem-categoria', 0),
(2, 'opção pai primeiro', 'pai-primeiro', 0),
(3, 'opção pai segundo', 'pai segundo', 0),
(4, 'opção pai terceiro', 'pai-terceiro', 0),
(5, 'filho do pai terceiro', 'mini-turtles', 0),
(6, 'neto do pai terceiro', 'neto-pai-terceiro', 0);
and table 2:
CREATE TABLE 'wp_term_taxonomy' (
'term_taxonomy_id' bigint(20) UNSIGNED NOT NULL,
'term_id' bigint(20) UNSIGNED NOT NULL DEFAULT '0',
'taxonomy' varchar(32) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT '',
'description' longtext COLLATE utf8mb4_unicode_520_ci NOT NULL,
'parent' bigint(20) UNSIGNED NOT NULL DEFAULT '0',
'count' bigint(20) NOT NULL DEFAULT '0'
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
INSERT INTO 'wp_term_taxonomy' ('term_taxonomy_id', 'term_id', 'taxonomy', 'description', 'parent', 'count') VALUES
(1, 1, 'category', '', 0, 0),
(2, 2, 'category', '', 0, 0),
(3, 3, 'category', '', 0, 0),
(4, 4, 'category', '', 0, 0),
(5, 5, 'category', '', 4, 0),
(6, 6, 'category', '', 5, 0);
Well, what happens here: When we use any form to insert values into a table saved in both, and in the second table is the link with the first field 'parent'.
In short: I wanted a function that would transform the data into the table in the array below:
$menu = array(
'casarão'=>array(
'mansão',
'cluble'
),
'casa'=>array(
'casebre'=>array(
'casa da mãe jona'=>array(
'casa do pai joão'=>array(
'casa do filho josé'=>array(
'casa do neto josefino'
)
)
)
)
),
'casinha'=>array(
'casarinha',
'casabela'
)
);