-1

In PHP I'm running a mysql query and from the results I want to string together multiple columns into a single variable. Obviously my example below doesn't work, but hopefully it gives you an idea of what I'm trying to do.

$var1=         $line_results[city,state,country];

I want var1 to become one long variable for all 3 columns that get stitched together. What is the exact syntax to stitch those 3 columns together? This is what I currently have setup and I want to merge them into one:

  $var1=        $line_results[city];
  $var2=        $line_results[state];
  $var3=        $line_results[country];
Alby
  • 426
  • 2
  • 7
  • 17

2 Answers2

3

Use . to concatenate strings e.g.

$var1 = $line_results['city'] . $line_results['state'] . $line_results['country'];

or if they need a space:

$var1 = $line_results['city'] .' '. $line_results['state'] .' '. $line_results['country'];

Hope this helps!

Rwd
  • 34,180
  • 6
  • 64
  • 78
1

You can concatenate strings with a dot. $var1 = $line_results[city] . $line_results[state] . $line_results[country]