What are some recommended practices for maintaining code cleanliness and modern standards when working with PHP and APIs?

One recommended practice for maintaining code cleanliness and modern standards when working with PHP and APIs is to follow the PSR (PHP Standards Recommendations) guidelines. These guidelines provide a set of coding standards that help ensure consistency and readability in your codebase. Additionally, using a modern PHP framework like Laravel or Symfony can help streamline API development and adhere to best practices.

// Example of adhering to PSR-2 coding standards
namespace App\Http\Controllers;

use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class UserController extends Controller
{
    public function index()
    {
        $users = User::all();
        return response()->json($users);
    }
}