Mr Chris Posted October 19, 2010 Share Posted October 19, 2010 Say I have an array like so: $var = array ("One","Two","Three","Four","Five","Six","Seven","Eight"); print_r($var); foreach ($var as $newname) { //Do something } and the print_r is recorded as Array ( [0] => One [1] => Two [2] => Three [3] => Four [4] => Five [5] => Six [6] => Seven [7] => Eight ) How in that foreach loop can I run an if statement which says if the element is greater than [5], then do something? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/216255-help-with-an-array/ Share on other sites More sharing options...
trq Posted October 19, 2010 Share Posted October 19, 2010 $var = array ("One","Two","Three","Four","Five","Six","Seven","Eight"); foreach ($var as $k => $newname) { if ($k > 5) { // do something } } Quote Link to comment https://forums.phpfreaks.com/topic/216255-help-with-an-array/#findComment-1123833 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.