Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] do.. while w php 8 ?, Dostosowuje skrypt do php 8 i jest problem z each()
starterrrrr
post
Post #1





Grupa: Zarejestrowani
Postów: 138
Pomógł: 0
Dołączył: 7.01.2015

Ostrzeżenie: (0%)
-----


Witam.

Dostosowuje skrypt do PHP 8.
Funkcja each() w php 8 jest już usunięta. Jak proponujecie przerobić poniższy kod na pasujący do php 8 ?

Pętla wykonuje kolejne iteracje w momencie gdy przekazana zmienna jest tablica.
  1.  
  2. do {
  3.  
  4. ...
  5.  
  6. } while (is_array($ilosc_lub_array) && list($klucz, $ilosc) = each($ilosc_lub_array));
  7.  


Ten post edytował starterrrrr 3.09.2021, 09:37:29
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




poprostu zrob tablice z tej zmiennej a ppotem foreach normalnie i po sprawie

  1. if (!is_array($ilosc_lub_array)) {
  2. $ilosc_lub_array = [$ilosc_lub_array];
  3. }
  4.  
  5. foreach ($ilosc_lub_array as $ilosc) {
  6. // tu twoj kod z while
  7. }
  8.  
Go to the top of the page
+Quote Post
starterrrrr
post
Post #3





Grupa: Zarejestrowani
Postów: 138
Pomógł: 0
Dołączył: 7.01.2015

Ostrzeżenie: (0%)
-----


Cytat(nospor @ 6.09.2021, 11:35:58 ) *
poprostu zrob tablice z tej zmiennej a ppotem foreach normalnie i po sprawie

  1. if (!is_array($ilosc_lub_array)) {
  2. $ilosc_lub_array = [$ilosc_lub_array];
  3. }
  4.  
  5. foreach ($ilosc_lub_array as $ilosc) {
  6. // tu twoj kod z while
  7. }
  8.  


Pierwszy raz widzę taki zapis (IMG:style_emoticons/default/ohmy.gif)
$ilosc_lub_array = [$ilosc_lub_array]; (IMG:style_emoticons/default/smile.gif)

Wieczorem sprawdzę.

Ten post edytował starterrrrr 6.09.2021, 11:25:05
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 14.10.2025 - 20:15