# Noob php question: calling functions

**URL:** <https://forum.kirupa.com/t/noob-php-question-calling-functions/197071>\
**Category:** programming\
**Created:** [August 13, 2006, 3:43pm UTC](https://forum.kirupa.com/t/noob-php-question-calling-functions/197071 "2006-08-13T15:43:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Decfor](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@Decfor](https://forum.kirupa.com/u/Decfor)\
**Post date:** [August 13, 2006, 3:43pm UTC](https://forum.kirupa.com/t/noob-php-question-calling-functions/197071/1 "2006-08-13T15:43:02Z")

</div>

hi. im fairly new to php, and there are a lot of things i dont understand:

i have the following code, and i want to be able to call it again if i need to. the code generates a random 8 character alpha-numerical string. i know its a crude way of doing it, and there are probably easier ways. if you know any, please do say.

```php
<?php
function randlink(){
//store alphabet into an array
$alphabet[0] = "a";
$alphabet[1] = "b";
$alphabet[2] = "c";
$alphabet[3] = "d";
$alphabet[4] = "e";
$alphabet[5] = "f";
$alphabet[6] = "g";
$alphabet[7] = "h";
$alphabet[8] = "i";
$alphabet[9] = "j";
$alphabet[10] = "k";
$alphabet[11] = "l";
$alphabet[12] = "m";
$alphabet[13] = "n";
$alphabet[14] = "o";
$alphabet[15] = "p";
$alphabet[16] = "q";
$alphabet[17] = "r";
$alphabet[18] = "s";
$alphabet[19] = "t";
$alphabet[20] = "u";
$alphabet[21] = "v";
$alphabet[22] = "w";
$alphabet[23] = "x";
$alphabet[24] = "y";
$alphabet[25] = "z";
//end alphabet array

/*store the functions into 2 arrays. one array chooses 4 random numbers. the other chooses 4 random letters. this way there is an even theoretical probability that a number or a letter will be chosen.*/
$alpha[0] = $alphabet[mt_rand(0,25)];
$alpha[1] = $alphabet[mt_rand(0,25)];
$alpha[2] = $alphabet[mt_rand(0,25)];
$alpha[3] = $alphabet[mt_rand(0,25)];

$number[0] = mt_rand(0,9);
$number[1] = mt_rand(0,9);
$number[2] = mt_rand(0,9);
$number[3] = mt_rand(0,9);
//end storing functions

/* create an array which stores the 2 arrays above (you'll see why later :P)*/
$outputter[0] = $alpha[0];
$outputter[1] = $alpha[1];
$outputter[2] = $alpha[2];
$outputter[3] = $alpha[3];
$outputter[4] = $number[0];
$outputter[5] = $number[1];
$outputter[6] = $number[2];
$outputter[7] = $number[3];

/* create an array. each variable calls a random number between 0 and 7. */
$randomiser[0] = mt_rand(0,7);
$randomiser[1] = mt_rand(0,7);
$randomiser[2] = mt_rand(0,7);
$randomiser[3] = mt_rand(0,7);
$randomiser[4] = mt_rand(0,7);
$randomiser[5] = mt_rand(0,7);
$randomiser[6] = mt_rand(0,7);
$randomiser[7] = mt_rand(0,7);

/*the foreach statement basically calls all 8 variables in the output array in a random order. each one of those outputs either a random letter or number. thus we have randomised the order in which the letters and numbers are outputted in.*/
foreach ($randomiser as $current) {
  $link=$link.$outputter[$current];
}
}
echo $link;

?>

```

ok, so, the 2 things i need to know are:

1. how do i call the function.

2. will php run the function without me calling it?

thanx in advance,  
Decfor
