Reputation: 469
I have 3 arrays $personal1 , $personal2 and $business , each one holds 1 field from each query, so for example 'Mr' 'John Smith' 'Johnscorp Ltd'.
I am trying to construct the following if query >>
$personal2 = $userinfo->leadname;
$personal1 = $userinfo->salutation;
$business = $userinfo->businessname;
if ($personal1=="")
$name = $business;
else
$name = $personal1;
echo '<h1>NAME:';
echo $name;
echo '</h1>';
What it does is check to see if the salutation is blank or not, if the field is blank the business name is echo'd instead.
The problem I have is how do I merge the personal and personal2 into one array ?.
I am not sure if I can do this :
$personal2 = $userinfo->leadname;
$personal1 = $userinfo->salutation;
$business = $userinfo->businessname;
if ($personal1=="")
$name = $business;
else
$name = $personal1 & $personal2;
echo '<h1>NAME:';
echo $name;
echo '</h1>';
or if I can do this ?
$personal = $userinfo->salutation,$userinfo->leadname;
$business = $userinfo->businessname;
if ($personal1=="")
$name = $business;
else
$name = $personal;
echo '<h1>NAME:';
echo $name;
echo '</h1>';
or if both are incorrect as I dont seem to be getting any results :-S .
Upvotes: 0
Views: 59
Reputation: 8980
I'm a bit puzzled because you've stated multiple times that you're using arrays, however in your example, it appears that you're using objects.
Anyways, if all you need is to merge $personal1 and $personal2, instead of using:
$name = $personal1 & $personal2;
you can just use:
$name = $personal1 + $personal2;
If it's a string you need:
$name = $personal1 . ' ' . $personal2;
Upvotes: 1
Reputation: 3024
I think the first example you have should be working, just replace
$name = $personal1 & $personal2;
with
$name = $personal1 . ' ' . $personal2;
this will join these string with a space between them
PS: Didn't you think strings instead of arrays ?
Upvotes: 1