How to generate unique order numbers in php: First, you can generate the order number in advance; then delete and save it; when you finally use it, just take one out and use it. The code is [$orderNo = date('YmdHis' ).substr(microtime(), 2, 5)].
##Related learningRecommendation:php programming(Video)
How to generate unique order numbers in php:
Idea: In order to prevent duplication, you can pre-generate order numbers for deduplication. Save it. For example, when saving the redis queue, just take one out and use it. 1. Preliminary - this may be repeated if there is a coincidencefunction genRequestSn($unique=0){ $orderNo = date('YmdHis').substr(microtime(), 2, 5) . mt_rand(10000,99999); return $orderNo; }
function genRequestSn($unique=0){ $orderNo = date('YmdHis').substr(microtime(), 2, 5) . mt_rand(10000,99999); if(!empty($unique)) $orderNo = $orderNo.$unique; return $orderNo; }
If you want to learn more about programming, please stay tunedphptraining column!
The above is the detailed content of How to generate unique order numbers in php. For more information, please follow other related articles on the PHP Chinese website!