I have 3 Variables.
$Full Name = 'John Smith'
$Address = '4732 E Cherry St'
$Type = array('Residential','Commercial');
I then need to check the $Type
to give me the END of my $JobName
so I will do the following...
if ($type == 'Residential') { $JobType = 'R'; }
else if ($type == 'Commercial') { $JobType = 'C'; }
I need to get the output of $JobName = 'Smith-4732-R'
So how do I strip the Last name from the $FullName
var, and only the address # from the $Address
to give me Smith-4732-R?
Revised Code...
$FullName = 'John Smith';
$Address = '4732 E Cherry St';
$Type = 'Residential';
$parts = explode(" ", $FullName);
$ClientLastName = array_pop($parts);
$parts = explode(" ", $Address);
$AddressSnip = print_r(array_slice($parts,0,1));
if ($Type == 'Residential') { $JobType = 'R'; }
else if ($Type == 'Commercial') { $JobType = 'C'; }
echo $ClientLastName . '-' . $AddressSnip . '-' . $JobType;
When I execute the above, I get the following. Array ( [0] = 4732 ) Smith-1-R
Try:
$FullName = explode(" ",$FullName);
$lastName = $FullName[sizeof($FullName)-1];
$Address = explode(" ",$Address);
$Address = $Address[0];
echo $lastName . '-' . $Address . '-' . $JobType;
It should be working. Hope it helps =)
Use the explode() function. E.g.:
$JobName = end(explode(" ",$FullName)).'-'.explode(" ",$Address)[0].'-'.$JobType;