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.
asked Apr 7, 2014 at 17:17
-
possible duplicate of Delete element from multidimensional-array based on valueElavarasan– Elavarasan2014年04月07日 17:23:31 +00:00Commented Apr 7, 2014 at 17:23
1 Answer 1
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] =>
)
)
answered Apr 7, 2014 at 17:21
Shankar Narayana Damodaran Shankar Narayana Damodaran
68.6k43 gold badges101 silver badges129 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Explore related questions
See similar questions with these tags.
lang-php