For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > April 2006 > Syntax problem for $x









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Syntax problem for $x
Garry Jones

2006-04-25, 7:01 pm

If the variable $delt1 is 8 I want the output

<td class="vt8" >

Which will have read the value of $delt1 from

<td class="vt<?= $delt1 ?>">

As this is part of a larger code I am trying to use x for the number in
$delt1

This:
<td class="vt<?= $delt.$x ?>">
does not work.

Any help greatly appreciated.

Garry Jones
Sweden


NC

2006-04-25, 7:01 pm

Garry Jones wrote:
>
> If the variable $delt1 is 8 I want the output
>
> <td class="vt8" >
>
> Which will have read the value of $delt1 from
>
> <td class="vt<?= $delt1 ?>">
>
> As this is part of a larger code I am trying to use x for the number in
> $delt1
>
> This:
> <td class="vt<?= $delt.$x ?>">
> does not work.


Try this:

<td class="vt<?php
$var = "delt$x";
echo $$var;
?>">

An even better solution would be to have an array called $delt and
store all data that are now the $delt* variables as array's elements.
This way, you could simply do:

<td class="vt<?= $delt[$x] ?>">

Cheers,
NC

Paul Haxter

2006-04-25, 7:01 pm

I prefer the following method.

<?php
echo '<td class="vt' . $delt . $x . '">';
?>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com