In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the example analysis of PHP7.1 square bracket array symbol multi-valued replication and specified key assignment usage, the content is very detailed, interested friends can refer to, hope to be helpful to you.
PHPer may all know the use of list, which simply means that you can assign values to multiple variables through an array in an expression test:
$values = array ('value1',' value2'); $list ($v1, $v2) = $values
Doesn't it feel convenient? In PHP 7.1, it is also easier to:
[$v1, $v2] = ['foo',' bar']
This is not the best part. In PHP 7.1, we can also specify key values to assign values, regardless of the order of the array elements:
List ('v1' = > $value1,' v2' = > $value2) = array ('v1' = >' foo', 'v2' = >' bar',...); / / or ['v1' = > $value1,' v2' = > $value2] = ['v1' = >' foo', 'v2' = >' bar',...]
In fact, in the era of PHP 5, there is a very good use of list may not be familiar with:
$arr = [['x','y'], ['x','y2'],]; foreach ($arr as list ($x, $y)) {echo $x,'', $y, PHP_EOL;}
By PHP 7.1, because you can specify a key assignment, this usage will be more flexible and probably more common:
$arr = [['x' = > 1,'y' = >'2'], ['x' = > 2,'y' = >'4'],]; foreach ($arr as ['x' = > $x,'y' = > $y) {echo $x,'', $y, PHP_EOL;}
Let's take a look at an example on the official website to see if it feels as refreshing as the spring breeze:
Class ElePHPant {private $name, $colour, $age, $cuteness; public function _ construct (array $attributes) {/ / $this- > name = $attributes ['name']; / / before / / now ["name" = > $this- > name, "colour" = > $this- > colour, "age" = > $this- > age, "cuteness" = > $this- > cuteness] = $attributes;} / /.}
It is worth mentioning that this way of assignment can be used in nesting!
[[$a, $b], [$c, $d]] = [[1,2], [3,4]]
Finally, there is a vision in the proposal of PHP 7.1, which is also very much to look forward to:
Class ElePHPant {private $name, $colour, $age, $cuteness; public function _ construct (["name" = > string $name, "colour" = >\ Colour $colour, "age" = > int $age, "cuteness" = > float $cuteness]) {$this- > name = $name; $this- > colour = $colour; $this- > age = $age; $this- > cuteness = $cuteness;} / /.}
If PHP introduces this syntax, the parameter list will no longer care about the parameter order, and PHP's buddies will no longer envy Ruby's buddies!
On the PHP 7.1 square bracket array symbol multi-value copy and specify key assignment usage example analysis is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.