Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- php function and change two loops to one loop?
- function test(){
- //some code
- $X_has_val = $Y_has_val= array();
- foreach ($A as $id => $row){
- if(is_take($id)){
- $X_has_val[$id] = $row;
- }
- }
- foreach ($B as $id => $row){
- if(is_take($id)){
- $Y_has_val[$id] = $row;
- }
- }
- //some code
- }
- function test(){
- //some code
- $X_has_val = $Y_has_val= array();
- foreach(array($A, $B) as $key=>$value){
- foreach ($value as $id => $row){
- if(is_take($id)){
- $X_has_val[$id] = $row;
- continue;
- $Y_has_val[$id] = $row;
- }
- }
- }
- //some code
- }
- $X_has_cc = array_filter($A, 'isTake');
- $Y_has_cc = array_filter($B, 'isTake');
- <?php
- test();
- function test() {
- $A = array(1,2,3,4,5,6,7,8,9,10);
- $B = array(99,100,101,102,103,104);
- $X_has_cc = array_filter($A, 'isTake');
- $Y_has_cc = array_filter($B, 'isTake');
- var_dump($X_has_cc, $Y_has_cc);
- }
- // select "even elements"
- function isTake($x) {
- return 0==$x%2;
- }
Add Comment
Please, Sign In to add comment