![]() |
The SplFileObject::key() is an inbuilt function of the Standard PHP Library (SPL) in PHP that is used to get the key (line number) of the current line pointed to by the SplFileObject. Syntaxpublic SplFileObject::key(): int ParameterThis function does not have any parameters. Return ValueThe SplFileObject::key() function returns the current line number in the form of an integer. The first line starts from 0 and the second line number is 1. Program 1: The following program demonstrates the SplFileObject::key() function. Before running this program you must save this file (“output.txt”) in your current working directory. PHP
output.txt: This is a text Simple example Another example here Output: Line 0: This is a text Line 1: Simple example Line 2: Another example here Program 2: The following program demonstrates the SplFileObject::key() function. Before running this program you must save this file (“output.txt”) in your current working directory. PHP
output.txt: Line 1 Line 2 Line 3 Line 4 Line 5 Output: Line 0: Line 1 Line 2: Line 3 Line 4: Line 5 Reference: https://www.php.net/manual/en/splfileobject.key.php |
Reffered: https://www.geeksforgeeks.org
PHP |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |