generate random number in php

To generate 6 digit random number code in php.

Following function will help you to generate random number.

<?php
function _generate_code(){
$character_set_array = array();
$character_set_array[] = array(‘count’ => 3, ‘characters’ => ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’);
$character_set_array[] = array(‘count’ => 3, ‘characters’ => ‘0123456789’);
$temp_array = array();
foreach ($character_set_array as $character_set) {
for ($i = 0; $i < $character_set[‘count’]; $i++) {
$temp_array[] = $character_set[‘characters’][rand(0, strlen($character_set[‘characters’]) – 1)];
}
}
shuffle($temp_array);
return implode(”, $temp_array);
}

echo _generate_code();