php array_push() -> How not to push if the array already contains the value

前端 未结 9 1961
无人共我
无人共我 2020-12-29 01:04

I am using the following loop to add items to an an array of mine called $liste. I would like to know if it is possible somehow not to add $value to the $liste array if the

9条回答
  •  无人及你
    2020-12-29 01:52

    Save logic and improve speed by keeping it logic-less. Just keep overwriting.

    $list = array();
    foreach ($something as $value) {
      if (!is_object($value) && !is_array($value)) {
        $list[$value] = $value
      }
    }
    $list = array_values($list);
    

提交回复
热议问题