我有一个数组$old_que_ans_session,它是
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
)
)
我需要根据数组中的元素值取消设置该元素。为此,我正在执行以下操作以获取密钥
$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.
如何解决这个问题。
使用 array_keys()
获取键的列表和您的$key1
值以挑选出相关的键...
$actualKey = array_keys($old_que_ans_session)[$key1];
在unset()
数组中的元素之前,您必须执行此操作,否则键将消失。