Home > Backend Development > PHP Tutorial > Dynamically add data to the array during foreach loop, foreach array_PHP tutorial

Dynamically add data to the array during foreach loop, foreach array_PHP tutorial

WBOY
Release: 2016-07-12 08:59:44
Original
1458 people have browsed it

Dynamicly add data to the array during the foreach loop, foreach array

Add data (we will give you an example here)

Result:

Dynamically add data to the array during foreach loop, foreach array_PHP tutorialforeach ($arr as &$v){···}, it is equal to $v=&$arr[$k]
$arr[$k] and $v At the same time, it points to the memory address of $arr[$k]. Even unset($v) only deletes the reference of $v to the memory space and does not delete the reference of $arr[$k] to the memory address, so $arr [$k] is still alive, so $arr naturally remains unchanged, so it should be like this

Result:

There is one more thing to note: &$kWhat is the result

Result:

It means: the key cannot be quoted, there is no such syntax format at all

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1096600.htmlTechArticleDynamicly add data to the array during foreach loop, foreach array dynamically add data to the array during foreach loop, once When working on a project, you need to dynamically add numbers to the array during foreach...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template