0

I need to use a var in an array:

$var = "abcd";
array( 'Bla: bla', 'Blo: $var', 'Bli: bli');

I'm totally noob at php and google has not answered me...

Thanks,

user3432152
  • 47
  • 1
  • 4

3 Answers3

2

As the others have said, you can use double quotes. Or you can technically use concatenation.

Double Quotes

array( 'Bla: bla', "Blo: $var", 'Bli: bli');

Concatenation

array( 'Bla: bla', 'Blo: ' . $var, 'Bli: bli');
muttley91
  • 12,278
  • 33
  • 106
  • 160
1

As others have mentioned, you can use double quotes or concatenation. You can also use => and leave the variable outside of the quotes. For example:

$var = "blah";

$tester = array("boo"=>$var);

echo $tester["boo"];  // results in blah
Matthew Johnson
  • 4,875
  • 2
  • 38
  • 51
0

Use double quotes ""

array( 'Bla: bla', "Blo: $var", 'Bli: bli');
                   ^         ^
Kamehameha
  • 5,423
  • 1
  • 23
  • 28