Php: what's the difference between $var and &$var?

前端 未结 5 1817
心在旅途
心在旅途 2021-02-18 22:36

What is the difference between

foreach ($my_array as $my_value) {
}

And:

foreach ($my_array as &$my_value) {
}
5条回答
  •  难免孤独
    2021-02-18 22:51

    A real world example for & use is when you need to change the content of an array with very few lines of code

    foreach($arrFeed as &$objFeed)
      $objFeed['externalSrc'] = convertToLocalImage($objFeed['externalSrc']);
    

提交回复
热议问题