<?phpClass ListNode { public $val = 0; public $next; public function __construct($val) { $this->val = $val; }}class Solution { public function mergeTwoLists(ListNode $l1, ListNode $l2) { if (!$l1) return $l2; if (!$l2) return $l1; $dummyHead = new ListNode(0); $current = $dummyHead; while ($l1 || $l2) { if (!$l1) { $current->next = $l2; break; } if (!$l2) { $current->next = $l1; break; } if ($l1->val < $l2->val) { $current->next = $l1; $current = $current->next; $l1 = $l1->next; } else { $current->next = $l2; $current = $current->next; $l2 = $l2->next; } } return $dummyHead->next; }}$l1 = new ListNode(1);$l1->next = new ListNode(2);$l1->next->next = new ListNode(4);$l2 = new ListNode(1);$l2->next = new ListNode(3);$l2->next->next = new ListNode(4);$cls = new Solution();$r = $cls->mergeTwoLists($l1, $l2);print_r($r);