Jump to content

Help with an array


Mr Chris

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/216255-help-with-an-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.