Advertisement
Virajsinh

Array Value Find And Replace Without Loop in PhP

Jul 30th, 2021
1,065
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.35 KB | None | 0 0
  1. <?php
  2.  
  3.     //Array Value Find And Replace Without Loop
  4.     $array = ['*pasta', 'cola', 'pizza'];
  5.     $search = '*';
  6.     $replace = '\*';
  7.     array_walk($array,
  8.         function (&$v) use ($search, $replace){
  9.             $v = str_replace($search, $replace, $v);    
  10.         }                                                                    
  11.     );  
  12.     print_r($array);
  13. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement