PHP microtime() Function
-- Learn not just technology, but also dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
PHP Tutorial
- PHP Tutorial
- PHP Introduction
- PHP Installation
- PHP Syntax
- PHP Variables
- PHP echo/print
- PHP EOF(heredoc)
- PHP Data Types
- PHP Type Comparison
- PHP Constants
- PHP Strings
- PHP Operators
- PHP If...Else
- PHP Switch
- PHP Arrays
- PHP Array Sorting
- PHP Superglobals
- PHP While Loops
- PHP For Loops
- PHP Functions
- PHP Magic Constants
- PHP Namespaces
- PHP Object-Oriented
- PHP Quiz
PHP Forms
- PHP Forms
- PHP Form Validation
- PHP Forms - Required Fields
- PHP Forms - Validate Email and URL
- PHP Complete Form Example
- PHP $_GET Variable
- PHP $_POST Variable
PHP Advanced Tutorial
- PHP Multidimensional Arrays
- PHP Date
- PHP Includes
- PHP Files
- PHP File Upload
- PHP Cookies
- PHP Sessions
- PHP E-mail
- PHP Secure E-mail
- PHP Error
- PHP Exception
- PHP Filters
- PHP Advanced Filters
- PHP JSON
PHP 7 New Features
PHP Database
- PHP MySQL Introduction
- PHP MySQL Connection
- PHP MySQL Create Database
- PHP MySQL Create Table
- PHP MySQL Insert Data
- PHP MySQL Insert Multiple Data
- PHP MySQL Prepared Statements
PHP microtime() Function
The microtime() function returns the current Unix timestamp with microseconds.
If the optional parameter get_as_float is set to TRUE, it returns a floating point number representing the Unix timestamp (in seconds).
Syntax
microtime(get_as_float)
Parameters
| Parameter | Description |
|---|---|
| get_as_float | Optional. If TRUE, the function returns a floating point number. If FALSE, it returns a string in the format "msec sec". |
Return Value
If get_as_float is TRUE, returns a float. Otherwise, returns a string like "0.123456 1234567890".
Example 1
<?php
echo microtime();
?>
Output:
0.12345600 1234567890
Example 2
<?php
echo microtime(true);
?>
Output:
1234567890.1234
Example 3
<?php
// Calculate script execution time
$start = microtime(true);
// Some code to execute
for ($i = 0; $i < 100000; $i++) {
// Do nothing
}
$end = microtime(true);
echo "Execution time: " . ($end - $start) . " seconds";
?>
Output:
Execution time: 0.0032 seconds
```
YouTip