2

I am trying to assign float value in php to variable I tried following,

$_web_lat=‎18.501059;
$_web_long=73.862686;

echo $_web_lat .'='. $_web_long;

[Parse error: syntax error, unexpected '.501059' (T_DNUMBER)]

OR

$_web_lat=floatval('‎18.501059');
$_web_long=floatval('‎‎73.862686');

echo $_web_lat .'='. $_web_long;

Both shows 0 as output? Anyone guide me on this?

SK IRT
  • 127
  • 1
  • 11
  • What is your version of php? `phpinfo();` – Adder Mar 19 '18 at 08:02
  • 1
    Possible duplicate of [PHP parse/syntax errors; and how to solve them?](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – JJJ Mar 19 '18 at 08:05

3 Answers3

11

Your code seems to have a hidden character ?

Try copy and use this:

<?php
$_web_lat=18.501059;
$_web_long=73.862686;

echo $_web_lat .'='. $_web_long;

?>
Karlo Kokkak
  • 3,674
  • 4
  • 18
  • 33
0

Try to write floating values like

<?php

    $_web_lat=floatval('‎18.501059f');
    $_web_long=floatval('‎‎73.862686f');


$float_value_of_var1 = floatval($_web_lat);
$float_value_of_var2 = floatval($_web_long);

echo $float_value_of_var1; // 18.501059
echo $float_value_of_var2; // ‎‎73.862686

?>
Xay
  • 248
  • 3
  • 10
0

the sintax error is caused by automatic string conversion do the string operator . (dot concat) if you want avoid this you could use or cast float value ast string

  $_web_lat=‎18.501059;
  $_web_long=73.862686;

  echo (string) $_web_lat .'='. (string>$_web_long;
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107