Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Zmiana funkcji each na inne rozwiązanie
xmarko
post
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

Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
xmarko
post
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);
}

}
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 28.12.2025 - 05:59