How to get array key from corresponding array value?

前端 未结 5 892
-上瘾入骨i
-上瘾入骨i 2020-12-01 16:12

You can easily get an array value by its key like so: $value = array[$key] but what if I have the value and I want its key. What\'s the best way to get it?

5条回答
  •  失恋的感觉
    2020-12-01 16:33

    You can use the array_keys function for that.

    Example:

    $array = array("blue", "red", "green", "blue", "blue");
    print_r(array_keys($array, "blue"));
    

    This will get the key from the array for value blue

提交回复
热议问题