Generate UUID Version 4 using PHP

ramsey/uuid library

  1. Add ramsey/uuid library to composer.json file:
"require": {
    "ramsey/uuid": "^4.2"
}
  1. Install library from the command line:
composer install
  1. Generate UUID Version 4:
<?php

use Ramsey\Uuid\Uuid;

require_once __DIR__.'/vendor/autoload.php';

$uuidV4 = (string) Uuid::uuid4();
echo $uuidV4;

Leave a Comment

Cancel reply

Your email address will not be published.