Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • foreach() function in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 108
    Comment on it

    foreach() function provides an easy way to scan arrays & exactly do the same thing like for loop, so this function is said to be PHP foreach loop. foreach loop works only on arrays.

    Syntax:

    foreach ($arrayname as $value) {}
    

    Example:
    In the below example, element of extension array is assigned to variable $x & array pointer is increment by one, until it reaches the last element of array.

    <?php
    $extension = array("com", "in", "co", "net");
    foreach ($extension as $x) {
        echo "$x <br>";
    }
    ?> 
    

    Output: com, in, co, net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: