Michael Falciglia
Michael Falciglia

Reputation: 1046

PHP - Adding echo statement into a link array

I'm trying to modify a link array in php to add a variable at the end of a link. I thought this was a very easy thing to do, but I keep erroring out when I do it. I'm not sure if I am missing syntax or if it is not possible to do it the way I am doing it.

Here is the array without any modifications and it works fine

$links[]=array(
"url"=>'?p=worksheet', // this is one way I tried, I also added ''
'name'=>'Worksheet',   // This is where the name I want displayed goes
'order'=>999999,
);
}

The variable I am trying to add is $cust_id

This is how I am trying to add it:

$links[]=array(
"url"=>'?p=worksheet'<?php echo $cust_id ;?>, // this is one way I tried, I also added ''
'name'=>'Worksheet',   
'order'=>999999,
);
}

Upvotes: 0

Views: 157

Answers (4)

Marc B
Marc B

Reputation: 360702

echo does output at the moment you call it. You're trying to concatenate two strings. And you also cannot embed PHP code within PHP code. Try

'url' => '?p=worksheet' . $cust_id,
                       ^^^^^^^^^^^

instead.

Upvotes: 2

rm-vanda
rm-vanda

Reputation: 3158

Use a concatenation operator: (of your choice):

$links = array(
"url"=>'?p=worksheet'.$cust_id, 
'name'=>'Worksheet{$cust_id}',   
'doubleQuotes'= "Make variables render $cust_id",
'finally' => $pre-tailored-variable;
);

where the last one would be have to made ahead of time:

$pre-tailored-variable = "String of some kind with value:".$value;

Upvotes: 1

cyberwombat
cyberwombat

Reputation: 40104

$links[]=array(
 "url"=>'?p=worksheet'.$cust_id,

Upvotes: 0

Dan H
Dan H

Reputation: 626

You can't inline functions like this in PHP...

$links[0]['url'] = '?p=worksheet' . $cust_id;

Might be what you're after.

Upvotes: 0

Related Questions