PHP关联数组和未设置[关闭]

I'm creating an irc bot and I have an array for Channels ($BotChannels = ['Channel' => [], 'Commands' => [], 'Type' => []];) The bot check on mysql when a new channel is added and when a old channel is removed and when the channel is removed i use a for to catch the channel position but when I use the unset function to remove the channel from array i always get an empty space on array code below.

if(count($BotChannels['Channel']) > 0) {
            for($i = 0; $i < count($BotChannels['Channel']); $i++) {
                if(!in_array($BotChannels['Channel'][$i], $TempChan)) {
                    IrcMsg($BotChannels['Channel'][$i], 'Channel removed from database, leaving.');
                    PartChannel($BotChannels['Channel'][$i]);
                    unset($BotChannels['Channel'][$i], $BotChannels['Commands'][$i] ,$BotChannels['Type'][$i]);
                }
            }
            unset($TempChan);
        }

First and foremost, your array structure of "$BotChannels" does not look like it can support holding SQL results man.

Therefore I would recommend the structure to be like the one below.

$BotChannels = [
  'key' => [  # "key" is your variable $i
     'Channel' => [],
     'Commands' => [],
     'Type' => []
  ],
];

And as for your Algorithm

if(count($BotChannels) > 0) {
   foreach (array_keys($BotChannels) as $key) { 
      if(!in_array($key, $TempChan)) {
      IrcMsg($key, 'Channel removed from database, leaving.');
      PartChannel($key);
      unset($BotChannels[$key]);
   }
   unset($TempChan);
}

If you insist on not changing your array "$BotChannels", then please make sure the SQL results are being populated exactly, how you want it to.

echo '<pre>'.print_r($BotChannels, 1).'</pre>'; # TIP