Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. $actions = array(
  2. array('action' => 'Action1', 'value' => '0'),
  3. array('action' => 'Action2', 'value' => '0'),
  4. );
  5.  
  6. foreach($actions as $item){
  7. if($item['action'] == 'Action1'){
  8. $item['value'] = 20;
  9. }
  10. }
  11.  
  12. foreach ($actions as &$item) {
  13. }
  14.  
  15. foreach($actions as $key => $val){
  16. if($val['action'] == 'Action1'){
  17. $actions[$key]['value'] = 20;
  18. }
  19. }
  20.  
  21. foreach($actions as &$item){ //<== add "&" reference to the $item that now when ever you change it the actions will change
  22. if($item['action'] == 'Action1'){
  23. $item['value'] = 20;
  24. }
  25. }
  26.  
  27. foreach($actions as $key => $item){
  28. if($item['action'] == 'Action1'){
  29. $actions[$key]['value'] = 20; // directly access $action and modify the value
  30. }
  31. }
  32.  
  33. foreach(array_keys($actions) as $key){
  34. $item = &$actions[$key];
  35. if($item['action'] == 'Action1'){
  36. $item['value'] = 20;
  37. }
  38. }
  39.  
  40. foreach($actions as &$item)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement