each () discontinued in PHP

1

How can I solve the obsolete each() problem (since php7.2) on code below?

            foreach($inputarr as $arr) {
                $sql = ''; $i = 0;
                //Use each() instead of foreach to reduce memory usage -mikefedyk
                while(list(, $v) = each($arr)) {
                    $sql .= $sqlarr[$i];
                    // from Ron Baldwin <ron.baldwin#sourceprose.com>
                    // Only quote string types
                    $typ = gettype($v);
                    if ($typ == 'string') {
                        //New memory copy of input created here -mikefedyk
                        $sql .= $this->qstr($v);
                    } else if ($typ == 'double') {
                        $sql .= str_replace(',','.',$v); // locales fix so 1.1 does not get converted to 1,1
                    } else if ($typ == 'boolean') {
                        $sql .= $v ? $this->true : $this->false;
                    } else if ($typ == 'object') {
                        if (method_exists($v, '__toString')) {
                            $sql .= $this->qstr($v->__toString());
                        } else {
                            $sql .= $this->qstr((string) $v);
                        }
                    } else if ($v === null) {
                        $sql .= 'NULL';
                    } else {
                        $sql .= $v;
                    }
                    $i += 1;

                    if ($i == $nparams) {
                        break;
                    }
                } // while
    
asked by anonymous 28.03.2018 / 21:08

1 answer

3

Use foreach instead of while and each

foreach($arr as $v) {
    
28.03.2018 / 21:14