To generate a UUID using PHP, you can use the ramsey/uuid
package. This package provides a simple API for generating and working with UUIDs in PHP. Here's an example code snippet that generates a random version 4 UUID:
main.php137 chars5 lines
This code first imports the Uuid
class from the ramsey/uuid
package. It then generates a version 4 UUID using the uuid4()
method. Finally, it outputs the UUID as a string using the toString()
method.
Note that you'll need to install the ramsey/uuid
package using Composer before you can use it. You can do this by adding ramsey/uuid
to your project's composer.json
file and then running composer install
:
57 chars6 lines
gistlibby LogSnag