-2

This is my code which is giving error

Parse error: syntax error, unexpected '24' (T_LNUMBER), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in C:\xampp\htdocs\block_gecko\front\index.php on line 186

echo '<td style="font-size: 120%;">' .$character->24hour . '</td>';
jps
  • 20,041
  • 15
  • 75
  • 79

1 Answers1

1

PHP variable cannot starts with a numeric character. Try this:

$var = '24hour' ;
echo '<td style="font-size: 120%;">' .$character->$var . '</td>';

Example :

$json = json_decode('{"24hour":"test"}');
$key = "24hour";
echo $json->$key; // "test"

Or convert your JSON as array (json_decode($data, true)) and use :

echo '<td style="font-size: 120%;">' .$character['24hour'] . '</td>';

Another way (Thanks @mickmackusa) :

$json = json_decode('{"24hour":"test"}');
var_dump($json->{'24hour'});
Syscall
  • 19,327
  • 10
  • 37
  • 52