I want to loop through an array and check if some elements is equal to a specific condition . For example , I want to remove the element contains "O" , so I can do in this way ..
@Array = ("Apple","Orange","Banana"); for ($i=0 ; $i <= $#Array ; $i++) { if( index($Array[$i],"O") >= 0 ) { splice(@Array,$i,1); } } but if I want to use foreach loop to replace for loop , how do I do ? because in foreach loop , there is no index so I can't use splice , unless I set a variable to store it .
forandforeachis the exact same thing, they are aliases. It is the C-style syntax that makes a difference.