I have an array like this:
Array ( [0] => Array ( [pid] => 8 [bv] => 0 [bs] => 0 ) [1] => Array ( [pid] => 11 [bv] => 0 [bs] => 0 ) [2] => Array ( [pid] => 10 [bv] => 0 [bs] => 0 ) )
as you see this array includes other arrays. Now I want to delete array with [pid] = 8 , for deleting that I need that array key but I don't know how to find the key of array that have pid=8 .
I tried this code but it doesn't work:
$key = array_search($pid, $cart_e); // $cart_e is above array
For Example:
For deleting array with pid = 8 I want the result be like this after deleting:
Array ( [1] => Array ( [pid] => 11 [bv] => 0 [bs] => 0 ) [2] => Array ( [pid] => 10 [bv] => 0 [bs] => 0 ) )
as you see the whole array is deleted (I need this code), in some case I just deleted pid that result become like this(I don't want this):
Array ( [0] => Array ( [bv] => 0 [bs] => 0 ) [1] => Array ( [pid] => 11 [bv] => 0 [bs] => 0 ) [2] => Array ( [pid] => 10 [bv] => 0 [bs] => 0 ) )
so, How to find the array key of a pid with specific id?
$res = array_filter(function ($x) { return $x['pid'] != 8;}, $array);elementit is into and checking