Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of PHP7 error reporting each function abandonment in the local environment of laravel project

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report