3v4l.org

run code in 300+ PHP versions simultaneously
<?php $result = []; $init_arr = [ ['name'=>'grape','num'=>2], ['name'=>'melon','num'=>1] ]; $result['init_arr'] = $init_arr; $removed_arr = my_remove_data( $init_arr, 2 ); $result['removed_arr'] = $removed_arr; array_unshift( $init_arr, ['name'=>'apple','num'=>3] ); $result['added_arr'] = $init_arr; var_dump( $result ); function my_remove_data( $arr, $id ){ foreach($arr as $k1=>$a) { foreach($a as $k2=>$b) { if($b == $id) { unset($arr[$k1]); } } } return $arr; }

preferences:
30.78 ms | 405 KiB | 5 Q