code: public static function serialize(array $links)
      {
          foreach ($links as $rel => $link) {
              if (is_array($link)) {
                  foreach ($link as $i => $l) {
                      $link[$i] = $l instanceof self ? array_filter((array) $l) : ['href' => $l];
                  }
                  $links[$rel] = $link;
              } elseif (!$link instanceof self) {
                  $links[$rel] = ['href' => $link];
              }
          }
  
          return $links;
      }
docs: Serializes a list of links into proper array format.
  @param array $links the links to be serialized
  @return array the proper array representation of the links.