Virajsinh

Array Remove By Value in PhP

Jul 30th, 2021 (edited)
664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.34 KB | None | 0 0
  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. ?>
Add Comment
Please, Sign In to add comment