100% Beats | PHP
Code

# Code
```php []
/**
 * Definition for a binary tree node.
 * class TreeNode {
 *     public $val = null;
 *     public $left = null;
 *     public $right = null;
 *     function __construct($val = 0, $left = null, $right = null) {
 *         $this->val = $val;
 *         $this->left = $left;
 *         $this->right = $right;
 *     }
 * }
 */
class Solution {

    /**
     * @param TreeNode $root
     * @param Integer $k
     * @return Integer
     */
    function kthSmallest($root, $k) {
        $stack = [];
        $current = $root;
        $count = 0;

        // Iterative inorder traversal
        while (!empty($stack) || $current !== null) {
            // Traverse to the leftmost node
            while ($current !== null) {
                $stack[] = $current;
                $current = $current->left;
            }

            // Pop from the stack
            $current = array_pop($stack);
            $count++;

            // If we have reached the kth smallest
            if ($count === $k) {
                return $current->val;
            }

            // Move to the right subtree
            $current = $current->right;
        }

        return null; // Should never reach here if input constraints are met
    }
}
```
['PHP']