从数组中获取第一个值

Jac*_*łło 1 php arrays

我有一个保存用户步骤的PHP数组:

array(
    'step_1' => 1,
    'step_2' => 1,
    'step_3' => 0,
    'step_4' => 0,
    'step_5' => 0
);
Run Code Online (Sandbox Code Playgroud)

所以,我的用户执行step_1和step_2,但他没有做其他步骤.现在,我希望获得他不做的第一步的名称,在这个例子中它是"step_3".

但是如果数组看起来:

 array(
    'step_1' => 1,
    'step_2' => 1,
    'step_3' => 1,
    'step_4' => 1,
    'step_5' => 0
);
Run Code Online (Sandbox Code Playgroud)

我想得到"step_5",比我知道用户不做step_5我可以,为exapmle重定向他们指定页面.我怎么才能得到它?

Law*_*one 6

你可以使用array_search()

See In Action

<?php 
$array = array(
    'step_1' => 1,
    'step_2' => 1,
    'step_3' => 1,
    'step_4' => 0,
    'step_5' => 0
);

$key = array_search(0, $array); // $key = step_4;

echo $key;
?>
Run Code Online (Sandbox Code Playgroud)