skip to Main Content

I am trying to move some PHP scripts from a PC running PHP version 7 to a PC running PHP version 8.
There is problem with following each() query:

    do {
        $Tabelle->SetLine(array_values($Line));
        foreach($Line as $Spalte => $Kapitel) {
            list($Name, $URL) = each($URLs[$Spalte]);           
            if ($URL == "") $Line[$Spalte] = $Name; 
            else            $Line[$Spalte] = '<a href="'.$URL.'">'.$Name.'</a>';    
        }
    } while (reset($Line) != "" || next($Line) != "" || next($Line) != "");

I have customized this as follows:

    do {
        $Tabelle->SetLine(array_values($Line));
        foreach($Line as $Spalte => $Kapitel) {
            foreach($URLs[$Spalte] as $Name => $URL)
                if ($URL == "") $Line[$Spalte] = $Name; 
                else            $Line[$Spalte] = '<a href="'.$URL.'">'.$Name.'</a>';    
        }
    } while (reset($Line) != "" || next($Line) != "" || next($Line) != "");

It runs on error in an infinite loop!

Then I adjusted it as follows:

        $Tabelle->SetLine(array_values($Line));
        foreach($Line as $Spalte => $Kapitel) {
            foreach($URLs[$Spalte] as $Name => $URL) {
                if ($URL == "") $Line[$Spalte] = $Name; 
                else            $Line[$Spalte] = '<a href="'.$URL.'">'.$Name.'</a>';    
                $Tabelle->SetLine(array_values($Line));
            }
        }

It works though:
On the old machine, several rows were displayed in 3 columns each.
Now also 3 columns, but 3 times as many rows as usual, and that is
first the values in the first column vary, the 2. and. 3. column remains the same
then the 1st and 3rd columns remain the same and the second varies
then the 1st and 2nd column stays the same and the third varies

2

Answers


  1. Chosen as BEST ANSWER

    I found this solution and it works. Using myEach() instead of each()

    function myEach(&$array)
    {
        $key = key($array);
        $result = ($key === null) ? false :
                  [$key, current($array), 'key' => $key, 'value' => current($array)];
        next($array);
        return $result;
    }
    

  2. I don’t know if your code was working before. but here is PHP8 compatible version of your code:

    do {
        $Tabelle->SetLine(array_values($Line));
        foreach($Line as $Spalte => $Kapitel) {
            $URL = current($URLs[$Spalte]);
            $Name = key($URLs[$Spalte]);
            next($URLs[$Spalte]);
            $Line[$Spalte] = $URL? '<a href="'.$URL.'">'.$Name.'</a>': $Name;
        }
    } while (reset($Line) != "" || next($Line) != "" || next($Line) != "");
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search