Virajsinh

Array Remove By Value in PhP

Jul 30th, 2021 (edited)
252
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     // Array Remove By Value
  3.     // https://stackoverflow.com/questions/8668826/search-and-replace-value-in-php-array
  4.     $array = [
  5.         'p_1',
  6.         'p_2',
  7.         's_1',
  8.         'p_4',
  9.     ];
  10.  
  11.     $post_remove = array('p_1', 'p_2', 'p_3', 'p_4');
  12.  
  13.     $a = array_values(array_diff($array, $remove));
  14.  
  15.     echo '<pre>', var_export($a), '</pre>';
  16. ?>
RAW Paste Data