How to solve the problem of PHP7 error reporting each function abandonment in the local environment of laravel project
How to solve the laravel project local environment PHP7 error each function waste problem, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.
Example 1:
Php7.1 writing method
If (is_array ($u)) {while (list ($key) = each ($u)) {$u = $u [$key]; break;}}
Change to php7.2 writing method
If (is_array ($u)) {$u = current ($u);} As PHP7.2 says, I suggest to use foreach () function as a substitute of deprecated each (). Here I let a couple of examples that works to me in Wordpress.---- as PHP7.2 said, I recommend using the foreach () function instead of the deprecated each (). Here are a few examples that are useful to me in Wordpress.
(OLD) while (list ($branch, $sub_tree) = each ($_ tree)) {.} (NEW) foreach ((Array) $tree as $branch = > $sub_tree) {.} (OLD) while ($activity = each ($this- > init_activity)) {.} (NEW) foreach ($this- > init_activity as $activity) {.} (old) while (list ($file) $info) = each ($this- > images)) (new) foreach ($this- > images as $file = > $info) {/ /.}
Example 2
16548 while (list ($id, $name) = each ($attr_ array [1]) {/ / 7.1I replaced the line with the next code in both lines and it worked, replaced by the following foreach ($attr_array [1] as $id = > $name) {/ / 7.2
Example 3: my example: an error occurred while generating a signature during payment
Public function createLinkString ($param) {$arg = ""; / / array sort ksort ($param); reset ($param); / / 7.1Writing / * while (list ($key, $val) = each ($param)) {if ($key = "sign") continue; if (! empty ($key)) {$arg. = $key. "=";} if (is_array ($val)) {$arg. = $this- > createLinkString ($val). Else {$arg. = $val. Write foreach ($param as $key = > $val) {if ($key = = "sign") continue; if (! empty ($key)) {$arg. = $key. "=";} if (is_array ($val)) {$arg. = $this- > createLinkString ($val). Else {$arg. = $val. "&";}} / / remove the last & character $arg = substr ($arg, 0, strlen ($arg)-1); return $arg;}
In short, in the php7.2 version, the each function is obsolete and cannot be used, so it is ok to replace it with foreach.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.