0

I have an array $old_que_ans_session which is

Array
(
    [1] => Array
        (
            [home] => https://s3.ap-south-1.amazonaws.com/bmimagedump/uploads/interior/design/1533365337.jpg
        )

    [3] => Array
        (
            [home] => https://s3.ap-south-1.amazonaws.com/bmimagedump/uploads/interior/design/1531557283.jpg
        )

    [4] => Array
        (
            [home] => https://s3.ap-south-1.amazonaws.com/bmimagedump/uploads/interior/design/1531557681.jpg
        )

)

I need to unset an element in the array based on its value. For that I am doing the following to get the key

$key1=array_search($da1, array_column($old_que_ans_session,$da));
unset($old_que_ans_session[$key1]);

where $da = home and $old_que_ans_session is the above mentioned array. The $key1 that I am getting is 2 but there is no key value as 2 in the above mentioned array.

How to solve this problem.

Shantanu
  • 148
  • 3
  • 12

1 Answers1

1

Use array_keys() to get a list of the keys and your $key1 value to pick out the relavant key...

$actualKey = array_keys($old_que_ans_session)[$key1];

You will have to do this before you unset() the element in the array, otherwise the key will have gone.

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55