[Resolved] Random function help please

SpaceshipSpaceship
Watch

shahzad11

Account Suspended
Impact
11
random function help please

i need a random function where i need to generate different names from two array

1. in one array 10 first names are listed
2. in 2nd array 10 second names are listed
3. the result will be created from 10x10 different combinations

ex: first name : shahzad , altaf, ansur
second name: Ahmad, Naseer, Anjum

and the result should be shown as under

Shahzad Ahmad
Shahzad Naseer
Shahzad Anjum
Altaf Ahmad
Altaf Naseer
Altaf Anjum
ansur Ahmad
ansur Naseer
ansur Anjum

advance thanks

regards to all
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
In which language?
 
0
•••
I believe you are looking for something along the lines of this:-

PHP:
<?php
$first_names = array('Peter',
'David',
'Michael',
'Jordan',
'Chris',
'Christopher',
'Ian',
'Stuart',
'Alan',
'Adam',
);

$last_names = array('McDonald',
'McKewan',
'Campbell',
'Boath',
'Killhooley',
'Haggart',
'McAllister',
'Benton',
'Low',
'Ashiem',
);

function rand_name($first_name, $last_name)
{
	$first = $first_name[rand(0, count($first_name) -1)];
	$last = $last_name[rand(0, count($last_name) -1)];
	return $first.' '.$last;
}
echo rand_name($first_names, $last_names);
?>
 
0
•••
yes this is like this but it should go on and on until all combinations are made
 
0
•••
okay then what you need is:-

PHP:
 <?php
$first_names = array('Peter',
'David',
'Michael',
'Jordan',
'Chris',
'Christopher',
'Ian',
'Stuart',
'Alan',
'Adam',
);

$last_names = array('McDonald',
'McKewan',
'Campbell',
'Boath',
'Killhooley',
'Haggart',
'McAllister',
'Benton',
'Low',
'Ashiem',
);

function rand_name($first_name, $last_name)
{
	$names_array = array();
    foreach ($first_name as $first)
    {
    	foreach ($last_name as $last)
    	{
    		$names_array[] = $first.' '.$last;
    	}
    }
    return $names_array;
}
print_r(rand_name($first_names, $last_names));
?>

Not necessarily the best way to do it but it works.
 
0
•••
thanks brother its all what i needed
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
CatchedCatched

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back