1

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
1

1 Answer 1

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] => 
 )
)

Demo

answered Apr 7, 2014 at 17:21
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.