str::random PHP Method

random() static public method

Generates a random string
static public random ( integer $length = false ) : string
$length integer The length of the random string
return string
    static function random($length = false)
    {
        $length = $length ? $length : rand(5, 10);
        $chars = range('a', 'z');
        $num = range(0, 9);
        $pool = array_merge($chars, $num);
        $string = '';
        for ($x = 0; $x < $length; $x++) {
            shuffle($pool);
            $string .= current($pool);
        }
        return $string;
    }

Usage Example

Ejemplo n.º 1
0
 public function add($data)
 {
     $data['id'] = str::random(32);
     $this->data[$data['id']] = $data;
     $this->save();
     return $data['id'];
 }
All Usage Examples Of str::random