PHP | getservbyport() Function Last Updated : 30 Aug, 2019 Comments Improve Suggest changes Like Article Like Report The getservbyport() function is an inbuilt function in PHP which returns the Internet service for given protocol and port number. Syntax: string getservbyport( int $port, string $protocol) Parameters: This function accepts two parameters as mentioned above and described below: $protocol: It is required parameter. It specifies the protocol name, like tcp, udp etc. $port: It is required parameter. It specifies the port number, like 80. Return Value: This function returns the Internet Service name on success. Note: This function is available for PHP 4.0.0 and newer version. Below programs illustrate the getservbyport() function in PHP: Program 1: php <?php // Use getservbyport() function to get // the Internet service which corresponds // to port and protocol $intservname = getservbyport(80, "tcp"); // Display the output echo $intservname; ?> Output: http Program 2: php <?php // Create an array of port numbers $port = array(21, 22, 23, 25, 80); // Loop run for each services foreach( $port as $index) { // Use getservbyport() function to get // the Internet service which corresponds // to port and protocol echo $index . ": " .getservbyport($index, "tcp") . "<br>"; } ?> Output: 21: ftp 22: ssh 23: telnet 25: smtp 80: http Reference: https://www.php.net/manual/en/function.getservbyport.php Comment More infoAdvertise with us Next Article PHP ksort() Function G gekcho Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | getservbyname() Function The getservbyname() function is an inbuilt function in PHP which returns the port number for given protocol and Internet service. Syntax: int getservbyname( string $service, string $protocol ) Parameters: This function accepts two parameters as mentioned above and described below: $protocol: It is r 2 min read PHP natsort() Function The natsort() function is an inbuilt function in PHP which is used to sort an array by using a ânatural orderâ algorithm. The natural order tells the order to be used as a normal human being would use. That is, it does not check the type of value for comparison. For example, in string representation 2 min read PHP ksort() Function The ksort() function is an inbuilt function in PHP which is used to sort an array in ascending order according to its key values. It sorts in a way that the relationship between the indices and values is maintained. Syntax: bool ksort( $array, $sorting_type ) Parameters: This function accepts two pa 3 min read PHP ksort() Function The ksort() function is an inbuilt function in PHP which is used to sort an array in ascending order according to its key values. It sorts in a way that the relationship between the indices and values is maintained. Syntax: bool ksort( $array, $sorting_type ) Parameters: This function accepts two pa 3 min read PHP ksort() Function The ksort() function is an inbuilt function in PHP which is used to sort an array in ascending order according to its key values. It sorts in a way that the relationship between the indices and values is maintained. Syntax: bool ksort( $array, $sorting_type ) Parameters: This function accepts two pa 3 min read PHP krsort() Function The krsort() function is an inbuilt function in PHP which is used to sort an array by key in reverse order according to its index values. It sorts in a way that relation between indices and values is maintained. Syntax: bool krsort( $array, $sorting_type ) Parameters: This function accepts two param 2 min read Like