in PHP find if a value of an inner array exists, then if found, delete the array -
i have simple 2 dimensional array. i'm trying write function finds if value exists in 1 of inner arrays. not hard. problem need delete entire inner array once found. that's i'm having trouble with. seems impossible using foreach loops.
anyway, here array. thanks!
$booksincart = array (array ('bookid' => 344, 'quantity' => 1), array ('bookid' => 54, 'quantity' => 1), array ('bookid' => 172, 'quantity' => 2), array ('bookid' => 3, 'quantity' => 1) );
use foreach
loop key , value. use key unset()
sub-array...
foreach ($booksincart $key => $sub) { if ($sub['bookid'] == 172) { unset($booksincart[$key]); } }
Comments
Post a Comment