over 9 years ago
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
<?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)