Reputation: 1449
I am trying to unset an array by value. I only have the ExerciseID
and need to unset
the array that it belongs too.
My array is structured like so:
Array
(
[0] => Array
(
[ExerciseID] => 644
[Sets] =>
[Reps] =>
)
[1] => Array
(
[ExerciseID] => 33
[Sets] =>
[Reps] =>
)
)
Many thanks in advance.
Upvotes: 1
Views: 152
Reputation: 68476
Loop through the array and check for the ExerciseID
key in your array with the value of your ExerciseID
and if found , unset and break up from the loop.
$exid=33;
foreach($arr as $k=>$arr1)
{
if($arr[$k]['ExerciseID']==$exid)
{
unset($arr[$k]);
break;
}
}
print_r($arr);
OUTPUT :
Array
(
[0] => Array
(
[ExerciseID] => 644
[Sets] =>
[Reps] =>
)
)
Upvotes: 1