有没有一种方法可以通过其位置而不是其键值来取消设置数组中的元素

时间:2018-08-09 07:15:15

标签: php arrays codeigniter

我有一个数组$ old_que_ans_session

set AppleScript's text item delimiters to ""
set tmpfile to ((path to temporary items folder as string) & "Pashua_" & (characters 3 thru end of ((random number) as string)) as string)

set fhandle to open for access tmpfile with write permission
write (config as string) to fhandle as «class utf8»
close access fhandle

set posixtmpfile to POSIX path of tmpfile

我需要根据其值取消设置数组中的元素。为此,我正在执行以下操作以获取密钥

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
        )

)

如何解决这个问题。

1 个答案:

答案 0 :(得分:1)

使用array_keys()获取密钥列表,并使用您的$key1值选择相关密钥...

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

unset()数组中的元素之前,您必须先执行此操作,否则键将消失。