开发者

PHP code - what does this part of code mean?

开发者 https://www.devze.com 2022-12-30 10:24 出处:网络
what does the assignment in this loop do? I don\'t get 开发者_StackOverflowthe array notation in it :S

what does the assignment in this loop do? I don't get 开发者_StackOverflowthe array notation in it :S

foreach($fieldvalues as $fieldvalue){
    $insertvalues[] = $fieldvalue;
 }


Add $fieldvalue to the end of the $insertvalues array.


$insertvalues[] means insert a new item into the array, its a shortcut of array_push(). Its also preferred as it created lesser overhead whilst the PHP is working.

Additional:

For those who are unsure how the loop works.

foreach($fieldvalues as $fieldvalue)

every time the loop... loops, the value $fieldvalue becomes the next value a pointer is looking it in the array $fieldvalues - thus adding this to a new array `$insertvalues by means of the shortcut syntax mentioned above.


It inserts a new item at the end of the array.

Other languages tend to have an append or push function for this.


It adds the value of $fieldvalue at the end of $insertvalues array. The [] creates an array and values of the specified variable are added to it at the end each time.


I think, This is variable for New Array.

0

精彩评论

暂无评论...
验证码 换一张
取 消