I ran into this code, foreach($vars as $a=>$var){ // some process here} and I wonder what is the difference when using foreach($vars as $var){ // some process here} ? Thanks.
I ran into this code, foreach($vars as $a=>$var){ // some process here} and I
Share
The operator
=>represents the relationship between a key and value. You can imagine that the key points=>to the value.EDIT:
foreachcan be used in two ways:Each time round the loop, the variable is set to the next value in the array.
Eg:
The above will display:
Only the values of the array are displayed.
Each time round the loop, the variables are set to the next key and value pair.
Eg:
The above will display:
Check the php foreach documentation for further reference