Check if a value exits in array (Laravel or Php)

前端 未结 4 726
天涯浪人
天涯浪人 2021-02-18 17:38

I have this array:

$list_desings_ids = array(\'hc1wXBL7zCsdfMu\',\'dhdsfHddfD\',\'otheridshere\');

With a die() + var_dumo() this array return

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-18 18:19

    instead array_key_exists you just type in_array this will solve your issue because if you dump your this array

    $list_desings_ids = array('hc1wXBL7zCsdfMu','dhdsfHddfD','otheridshere');
    

    output will be,

    array(
       0 => hc1wXBL7zCsdfMu,
       1 => dhdsfHddfD,
       2 => otheridshere
    )
    

    so your code array_key_exists will not work, because here in keys 0,1,2 exists, So, you want to check values,so for values, just do this in_array it will search for your desire value in your mentioned/created array

提交回复
热议问题