Virajsinh

Array Value Find And Replace Without Loop in PhP

Jul 30th, 2021
648
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. ?>
RAW Paste Data