How to solve a depreciated each() problem?

Asked

Viewed 34 times

-1

My code

elseif (is_array($image)) {
        list($key, $width) = each($image);
        list($key, $height) = each($image); 

        $image = imagecreatetruecolor($width, $height);

    }

This excerpt is appearing a Notice de each depreciado. How to solve?

  • Deprecated is a false cognate, like many words in English. For example, the word library gives impression that it is "bookstore", but means "library" (totally different). The term "depreciated" means something that has been diminished in value or price, which is quite different from "obsolete", which would be the most appropriate translation.

2 answers

2

It’s not necessary foreach to perform an operation so simple which can be written, if image is an array of 2 values (probably more, and probably used getimagesize), if you have this:

array(7) {
   [0]=> int(2048) 
   [1]=> int(852) 
   [2]=> int(2) 
   [3]=> string(25) "width="2048" height="852"" 
   ["bits"]=> int(8) 
   ["channels"]=> int(3) 
   ["mime"]=> string(10) "image/jpeg"
}

Just set directly:

$width = $image[0]; //0 é o indice da largura
$height = $image[1]; //1 é o indice da largura

$image = imagecreatetruecolor($width, $height);

An extra note, as I have already commented in another publication:

... «depreciated» is the wrong translation and this being misused and confused with the correct word, «depreciated» in English is «depreciated» and not «deprecated». The word «deprecated» that would be correct to refer to this would be translated as «obsolete», «disapproved», «censured». In the case of use here the best with certainty is «obsolete». Summarizing «depreciated» and «depreciated» has nothing to do with it

  • 1

    Thanks for the Portuguese lesson and help.

-2

I resolved

foreach($image as $key=>$v){
            ($key == 0) ? $width = $v : $height = $v;
        }
        $image = imagecreatetruecolor($width, $height);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.