🌐
PHP
php.net › manual › en › function.end.php
PHP: end - Manual
<?php private function extension($str){ $str=implode("",explode("\\",$str)); $str=explode(".",$str); $str=strtolower(end($str)); return $str; } // EXAMPLE: $file='name-Of_soMe.File.txt'; echo extension($file); // txt ?> Very simple.
🌐
Tutorial Republic
tutorialrepublic.com › php-reference › php-end-function.php
PHP end() Function - Tutorial Republic
Run this code » · <?php // Sample array $colors = array("red", "green", "blue", "orange", "yellow", "black"); // Getting the last element echo end($colors); // Prints: black ?> The end() function accepts the following parameters.
🌐
W3Schools
w3schools.com › php › func_array_end.asp
PHP end() Function
json_decode() json_encode() json_last_error() PHP Keywords · abstract and as break callable case catch class clone const continue declare default do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile extends final finally fn for foreach function global if implements include include_once instanceof insteadof interface isset list namespace new or print private protected public require require_once return static switch throw trait try use var while xor yield yield from PHP Libxml
🌐
w3resource
w3resource.com › php › function-reference › end.php
PHP: end() function - w3resource
The end() function is used to move the internal pointer of an array to its last element.
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-end-function
PHP end() Function - GeeksforGeeks
September 16, 2024 - <?php // Input array $arr = array('Ram', 'Shita', 'Geeta'); // End function print the last // element of the array. echo end($arr); ?> ... Example 2: This example illustrates retrieving the last element from an array.
🌐
Jobtensor
jobtensor.com › Tutorial › PHP › en › Array-Functions-end
PHP Built-in end(), Definition, Syntax, Parameters, Examples | jobtensor
end(array) <?php // Example 1 $cities = array("New York", "Salt Lake", "Tokyo"); echo current($cities) . "<br>"; echo end($cities) . "<br>"; // Examples in conjuction with other related functions $ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28); echo current($ages) .
🌐
Tutorialspoint
tutorialspoint.com › php › php_function_end.htm
PHP - Function end()
The end() function advances array's internal pointer to the last element, and returns its value. It returns the last element in an array. Try out following example − · <?php $transport = array('foot', 'bike', 'car', 'plane'); $mode = current($transport); print "$mode <br />"; $mode = next($transport); print "$mode <br />"; $mode = current($transport); print "$mode <br />"; $mode = prev($transport); print "$mode <br />"; $mode = end($transport); print "$mode <br />"; $mode = current($transport); print "$mode <br />"; ?> This will produce the following result − ·
🌐
AthenaLinks
athenalinks.com › home › programming & tech › php tutorial › php end function
PHP end function - AthenaLinks
February 24, 2024 - In the aforementioned example, the “end” function is applied to the array “$colors”, retrieving the last element, which is then stored in the variable “$lastColor”. The value is subsequently displayed, exemplifying the ...
🌐
3D Bay
clouddevs.com › home › php guides › guide: how to use php’s end() function
A Deep Dive into PHP's end() Function
May 19, 2025 - The most common use case for end() ... involving dynamic arrays where the size and content may vary. ```php $numbers = [1, 2, 3, 4, 5]; echo "The last number is " ....
Find elsewhere
🌐
SitePoint
sitepoint.com › php
What is the correct way to exit or end a php script if a particular process fails - PHP - SitePoint Forums | Web Development & Design Community
July 3, 2022 - execute()){ echo 'Congratulation, your account has been created '; } else { echo 'Sorry, there was a problem creating your account - please contact site admin '; } When a failure occurs, can I use die("Houston we have a problem"); o...
Top answer
1 of 4
14

Heredoc syntax:

A third way to delimit strings is the heredoc syntax: <<<. After this operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation.

The closing identifier must begin in the first column of the line. Also, the identifier must follow the same naming rules as any other label in PHP: it must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore.

Warning It is very important to note that the line with the closing identifier must contain no other characters, except a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including Mac OS X. The closing delimiter must also be followed by a newline.

If this rule is broken and the closing identifier is not "clean", it will not be considered a closing identifier, and PHP will continue looking for one. If a proper closing identifier is not found before the end of the current file, a parse error will result at the last line.

Heredocs can not be used for initializing class properties. Since PHP 5.3, this limitation is valid only for heredocs containing variables...

2 of 4
1

Read it here: http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

🌐
W3docs
w3docs.com › learn-php › endforeach.html
endforeach
Let's look at some practical examples of how the "endforeach" keyword can be used: <?php // Example 1 $array = ["apple", "banana", "cherry"]; foreach ($array as $value): echo $value .
🌐
O'Reilly
oreilly.com › library › view › php-in-a › 0596100671 › re49.html
exit() - PHP in a Nutshell [Book]
October 13, 2005 - Content preview from PHP in a Nutshell · exit() void exit ( [mixed status] ) The exit() function takes just one optional parameter and immediately terminates execution of the script.
Author   Paul Hudson
Published   2005
Pages   372
Top answer
1 of 2
66

This is well documented. From the PHP Manual:

The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include() or require(), so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later. It is also handy if you use output buffering, and would not like to see added unwanted whitespace at the end of the parts generated by the included files.

Omitting the closing tag helps you prevent accidental whitespace or newlines from being added to the end of the file.

2 of 2
20

That's a core PHP feature: unlike other languages, you need to tag PHP code with a special tag (normally <?php) because everything else is considered literal output:

This is not PHP
<?php

echo 'This is PHP' . PHP_EOL;

?>
This is not PHP either
D:\tmp>php test.php
This is not PHP
This is PHP
This is not PHP either

Although the manual mentions HTML, PHP doesn't really know/care what content-type is outside its tags.

If you forget to close a PHP block when further stuff follows you normally get a syntax error:

This is not PHP
<?php

echo 'This is PHP' . PHP_EOL;

This is not PHP either
D:\tmp>php test.php
PHP Parse error:  syntax error, unexpected 'is' (T_STRING) in D:\tmp\borrame.php on line 6

Blank lines are a sort of special case because they are valid and almost invisible in almost all languages (PHP, HTML, CSS, JavaScript...) so they often unnoticed.

Once you've removed the ?> tag, your literal blank lines have disappeared from the script output because they've become part of the PHP code (and, as such, they've started to get ignored).

Of course, blank lines are ignored by PHP but not necessarily by whatever you are generating which, as I said, does not need to be HTML: it can be a picture, a PDF document, an Excel spreadsheet. Bogus white lines can be easily avoided by not closing the last PHP block when it's the last part of the file.

🌐
W3docs
w3docs.com › learn-php › end.html
Understanding PHP's array end() function
In this article, we've taken a detailed look at the end() function in PHP, including its syntax, usage, and common pitfalls. While it may seem like a simple function, there are some important nuances to be aware of when using it.