Jump to content

Recommended Posts

Hello guys and gals,

 

Look at the following code:

 

if ($carrier == "Chautauqua Airlines") {
$reg_number = rand (100, 999);
$reg_number = "N".$reg_number."SK";
}

 

As you can see, if $carrier equals Chautauqua Airlines, then it will make a random number from 100-999 and build the following result: N###SK

 

What I want to know is how can I also make this code so that instead of always using SK, it would randomly select between using SK or JQ or RP?

 

Thanks for any help, as always.

 

Regards,

 

ERuiz

Link to comment
https://forums.phpfreaks.com/topic/75012-solved-random-letter/
Share on other sites

<?php

$random_letter_ucase = chr(rand(ord("A"), ord("Z"))); 


if ($carrier == "Chautauqua Airlines") {
$reg_number = rand (100, 999);
$reg_number =  ($random_letter_ucase+1),$reg_number,($random_letter_ucase+1);

///should output something like  FG###SD
}?>

Link to comment
https://forums.phpfreaks.com/topic/75012-solved-random-letter/#findComment-379299
Share on other sites

darkfreaks remember shuffle will shuffle an array BUT whats does it return!!!

 

shuffle($array);

not

$randarray=shuffle($array); as it returns a boolean ;)

 

EDIT: oh if you must have different random items then shuffle works well

ie

<?php
$array= array("SK","JQ","RP");
shuffle($array);
echo $array[0]; echo $regnumber; echo $array[1]; ?>

which i think darkfreaks  was aiming for

Link to comment
https://forums.phpfreaks.com/topic/75012-solved-random-letter/#findComment-379315
Share on other sites

<?php
$array= array("SK","JQ","RP");
$randarray= array_rand($array);
$randarray2= array_rand($array);
echo $array[$randarray]; sprintf($regnumber); echo $array[$randarray2]; ?>

 

 

 

Thanks! That did the trick! Also MANY thanks to darkfreaks, who also helped out. Thanks to both you guys.

 

ERuiz

Link to comment
https://forums.phpfreaks.com/topic/75012-solved-random-letter/#findComment-379319
Share on other sites

in darkfreaks defence i have seen LOTS of people attempt shuffle like that..

 

also please be aware.. that the code you use will allow results like SK###SK and JQ###JQ where as the following code will not..

 

EDIT: oh if you must have different random items then shuffle works well

ie

<?php
$array= array("SK","JQ","RP");
shuffle($array);
echo $array[0]; echo $regnumber; echo $array[1]; ?>

which i think darkfreaks  was aiming for

Link to comment
https://forums.phpfreaks.com/topic/75012-solved-random-letter/#findComment-379324
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.