Tech

En till Good Old Blogs webbplats

Ensuring that values are in an array

I’ve run across situations where I want to ensure that some values exist in a non-associative array (without getting duplicates). The way I’ve usually solved it is: if (!in_array(‘nid’, $fields)) { $fields[] = ‘nid’; } if (!in_array(‘title’, $fields)) { $fields[] = ‘title’; } This is kind of ugly, and the more values you want to…

Läs mer