您的位置 首页 php

[PHP] foreach循环的引用赋值中出现的问题

foreach($arr as &$value)
1.引用赋值符号&,是每次循环的时候,把当前元素变成地址,$value变量就是对应元素的地址,循环结束$value是一个指向最后一个元素的地址
2.当我下次循环,使用了这种方式foreach($arr as $value) ,会出现问题;foreach会把每个元素赋值给后面的$value变量
3.因此,逻辑就变成了,把每个元素修改给原数组的最后一个元素,最后一次循环会一直是前一次的结果
4.最好不用引用传递,用这种形式$arr[$key]改原数组,或者在下次循环时候换一个变量名

$nums=array(1,2,3);foreach($nums as &$v){        var_dump($v);}/*int(1)int(2)int(3)*/var_dump($nums);/*array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  &int(3)}*/foreach($nums as $v){        var_dump($v);}/*int(1)int(2)int(2)*/

【相关教程:PHP视频教程】  

以上就是[PHP] foreach循环的引用赋值中出现的问题的详细内容,更多请关注求知技术网其它相关文章!

文章来源:智云一二三科技

文章标题:[PHP] foreach循环的引用赋值中出现的问题

文章地址:https://www.zhihuclub.com/5808.shtml

关于作者: 智云科技

热门文章

评论已关闭

24条评论

  1. 0002; Pearson s correlation Extended Data Fig This group showed that after a hypoxic event the Pigf knockout mouse displayed a delayed angiogenic response and an increased BBB permeability to endogenous fibrinogen

  2. antithrombin, protein C PC, protein S, homocysteine, activated PC resistance, factor V Leiden FVL and prothrombin PT mutations was prospectively evaluated

  3. Does Fat Burner Oral Interact with other Medications Once trained on the project at the first year, I continued proposing ideas and procedures

  4. Secondly, bacteria may influence the pathogenesis of cancers directly via the secretion of bacterial effector proteins using type 3 or type 4 secretion systems T3SS T4SS, which could affect the cell proliferation, cytoskeletal rearrangements, activation of NF KB and inhibition of cellular apoptosis 60, 61

  5. Importantly, circulating levels of testosterone, androstenedione, and DHEA S increase in women on AI therapy 13 as compared with pretreatment levels

  6. By the time the tumor has doubled twenty three times, the original cancer cell has multiplied to more than eight million Schwartz J, Padmanabhan A, Aqui N, Balogun RA, Connelly Smith L, Delaney M, Dunbar M, Dunbar NM, Witt V, Wu Y, Shaz BH

  7. 43 1988 USA Cross- sectional n 60 runners who ran at least 3 per week for a minimum of a year; 28 males and 32 females; prevented runners n 30 vs

  8. Improving Female Fertility Before we discuss the interventions researched to enhance fertility in women, it is interesting to note that far more research exists on interventions for men

  9. The case for albumin estradiol decreases levels of magnesium chloride by Other see comment

  10. a and b, E 2 induced regression of late passage MCF 7TAM tumors a mean of 20 tumors group

  11. somethin s wrong Therefore, Transparency Is Something To Check Before Buying A Weight Reduction Capsule If The Producers Are Transparent About Their Products, You Possibly Can Depend On Them And What Was The Weight Loss Product On Shark Tank coffee on a keto diet Go For The Products With Out Hesitation Most Importantly, It S Important To Check Whether A Product Is Price rate of weight loss Investing In Or Not Before You Try To Purchase A Weight rate of weight loss Reduction Pill

  12. This article looks at what doxycycline can and cannot do, how it should be used, and what side effects you might expect while taking it At a dose of 1000 Ојg day, tumor tamoxifen and its active metabolites were detected in high concentrations ranging up to 6 mmol g tissue

  13. A dermatologist can tell you what can help clear your stubborn acne 345 150 mg Caja x 14 cГЎps

  14. and in the global arena Indeed, therapists who regularly treat patients experiencing secondary infertility say that what makes the condition particularly isolating is that it can be perceived by others as a selfish obsession

  15. According to Keiichi Morishita in his book, Hidden Truth of Cancer, as blood starts to become acidic, the body deposits acidic substances in cells to get them out of the blood Cefamandole can be used in the treatment skin and skin structure infections, respiratory infections, and urinary tract infections

  16. In pre renal disease, the ratio is close to 20 1, while in intrinsic renal disease, it is closer to 10 1

网站地图