really simple question.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mattyboi
Forum Commoner
Posts: 34
Joined: Mon Feb 06, 2006 9:42 pm

really simple question.

Post by mattyboi »

Hey guys,

I am embarressed to even ask this question.

I am trying to combine a varible with the value of '1' with the letter 'a' and assigning it to a new varible.

Code: Select all

<?php
$i = 1;
$check = "$i'a'";
echo("$check");
?>
The output should be "1a".

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

<?php
$i = 1;
$check = $i . 'a';
echo($check);
?>
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Alternatively:

Code: Select all

$check = "{$i}a";
See string interpolation.
User avatar
No0b
Forum Commoner
Posts: 37
Joined: Tue Feb 07, 2006 6:17 pm

Post by No0b »

The

Code: Select all

.
in fayds post means it's concatenating your $i var with the string "a". Concatenating means to on to. For example:

Code: Select all

$results = "$i";

//then concatenate the var

$results .= "a"
the .= is concatenating the var $results with a new string. This is useful when you want to keep a value of a var and add to it.
Post Reply