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.

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.