Tag: PHP

Sample PHP array building and key search

We will base our code off; http://php.net/manual/en/function.array-key-exists.php

Referred as: bool array_key_exists ( mixed $key , array $array )

<?PHP
global $known_room_list; // accessible from inside the functions without session/cookie/sql
$known_room_list = array(); // get the array ready for keys

function do_something($room){
   global $known_room_list;
   if (!array_key_exists($room,$known_room_list)){
     // Do something only once per room
     $known_room_list[] = $room; // add to array
   }
}

do_something("new-slack-room");
?>