In PHP we use....
foreach ($array as $value) {
echo $value;
}
In Java the same thing can be done using
for (int e : array) {
System.out.println(e);
}
is there any difference between the above 2 code segments
In PHP we use....
foreach ($array as $value) {
echo $value;
}
In Java the same thing can be done using
for (int e : array) {
System.out.println(e);
}
is there any difference between the above 2 code segments
This is very close to what both forms of java for-each iterator (numeric and Iterator) do, but PHP iterator also can provide keys and bind the iterated value by-reference, so you could modify it in place if you wanted to.
I'm not very familiar with Java but your example suggests you need specify a data type for the index. PHP is loosely typed so you can use a foreach loop on associative and mixed arrays, not only pure numeric arrays. But, it's also possible to foreach your own custom objects just by implementing the Iterator interface.