Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • each and reset function php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 103
    Comment on it

    Welcome to FindNerd. We are going to discuss the in-build functions reset and each. each works like a loop. It returns the current element and move the pointer forward. reset moves the pointer to first element. Please have a look.

    <?php
    $salaryArr = array('deepak'=>30000,'umesh'=>34343,'kamal'=>23232);
    echo $nextele= next($salaryArr);
    reset($salaryArr);
    while (list($key, $val) = each($salaryArr)) {
    echo $key . ' salary is ' . $val . '<br/>';
    }
    ?>
    result:
    34343
    deepak salary is 30000
    umesh salary is 34343
    kamal salary is 23232
    

    In above example we created an array with three records. firstly we tried to get the salary but we were unable to get the username from the array by using next function. After that we decided to use the each function for this. we moved the pointer to first element by using reset function and started the while loop with the help of each and list function.

 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: