Post
#1
|
|
|
Grupa: Zarejestrowani Postów: 59 Pomógł: 0 Dołączył: 26.02.2004 Ostrzeżenie: (0%)
|
Cześć, Mam taki kawałek kodu, który znalazłem w sieci: while ($loop && ( ( $option = each($children[$parent]) ) || ( $parent > $root_id ) )) { Proszę o pomoc w modyfikacji kodu: $option = each($children[$parent]) Programuję w PHP w wolnym czasie.... W wersji PHP 7.2 - pokazuje mi błąd funkcji. Funkcję each - powinienem zmienić na : foreach ($children[$parent] as $option) Jednak w nie mogę takiego zapisu wykorzystać w pętli while. Prosze o jakieś sugestie zmiany kodu |
|
|
|
![]() |
Post
#2
|
|
|
Grupa: Zarejestrowani Postów: 59 Pomógł: 0 Dołączył: 26.02.2004 Ostrzeżenie: (0%)
|
Zrobilem tak, jednak nie działa: foreach ($children[$parent] as $option){ if ($loop &&(( $parent > $root_id ))){ Cały kod funkcji przed zmianami: while ($loop && ( ( $option = each($children[$parent]) ) || ( $parent > $root_id ) )) { if ($option === false) { $parent = array_pop($parent_stack); // HTML for menu item containing childrens (close) $html[] = str_repeat("\t", ( count($parent_stack) + 1 ) * 2) . '</ul>'; $html[] = str_repeat("\t", ( count($parent_stack) + 1 ) * 2 - 1) . '</li>'; } elseif (!empty($children[$option['value']['id']])) { $tab = str_repeat("\t", ( count($parent_stack) + 1 ) * 2 - 1); // HTML for menu item containing childrens (open) $this->html[] = sprintf( '%1$s<li><a href="%2$s">%3$s</a>', $tab, // %1$s = tabulation $option['value']['link'], // %2$s = link (URL) $option['value']['title'] // %3$s = title ); $this->html[] = $tab . "\t" . '<ul class="submenu">'; array_push($parent_stack, $option['value']['parent_id']); $parent = $option['value']['id']; } else // HTML for menu item with no children (aka "leaf") $this->html[] = sprintf( '%1$s<li><a href="%2$s">%3$s</a></li>', str_repeat("\t", ( count($parent_stack) + 1 ) * 2 - 1), // %1$s = tabulation $option['value']['link'], // %2$s = link (URL) $option['value']['title'] // %3$s = title ); } // HTML wrapper for the menu (close) $this->html[] = '</ul>'; return implode("\r\n", $this->html); } } |
|
|
|
xmarko [PHP]Zmiana funkcji each na inne rozwiązanie 21.01.2021, 20:21:56
vokiel Musisz dodać jeszcze if w foreach i sprawdzać waru... 22.01.2021, 09:53:31
kamil_lk CytatMusisz dodać jeszcze if w foreach i sprawdzać... 22.01.2021, 22:03:11
xmarko Zamieniłem while na
foreach ($children[... 22.01.2021, 22:45:20
vokiel Przeanalizuj kod i pomyśl co sprawdza if i czy te ... 23.01.2021, 11:59:39 ![]() ![]() |
|
Aktualny czas: 28.12.2025 - 05:59 |