What are the key differences between IMAP and POP3 protocols in terms of accessing and managing email accounts?

IMAP (Internet Message Access Protocol) allows users to access and manage emails directly on the mail server, keeping emails synchronized across multiple devices. POP3 (Post Office Protocol) downloads emails from the server to the user's device, making it more suitable for offline access but less efficient for managing emails across multiple devices.

// Example code snippet using IMAP to access and manage emails
$imap_server = '{mail.example.com:993/imap/ssl}INBOX';
$imap_username = 'username@example.com';
$imap_password = 'password';

$inbox = imap_open($imap_server, $imap_username, $imap_password);

// List all emails in the inbox
$email_list = imap_search($inbox, 'ALL');

// Close the IMAP connection
imap_close($inbox);
``` 

```php
// Example code snippet using POP3 to access and manage emails
$pop3_server = 'mail.example.com';
$pop3_port = 995;
$pop3_username = 'username@example.com';
$pop3_password = 'password';

$inbox = pop3_open($pop3_server, $pop3_port, $pop3_username, $pop3_password);

// Download and process emails from the server
$email_count = pop3_get_messages_count($inbox);

// Close the POP3 connection
pop3_close($inbox);