0

I have (from database):

<?php
$l = array();
$l['lat'] = $row['lat']; //51.507351
$l['lon'] = $row['lon']; //-0.127758
$l['animation'] = $row['animation']; //google.maps.Animation.DROP - stored without quotes in database
?>

If I var_dump($l):

array(3) { ["lat"]=> string(9) "51.507351" ["lon"]=> string(9) "-0.127758" ["animation"]=> string(26) "google.maps.Animation.DROP" }

Then "google.maps.Animation.DROP" is in quotes. How to avoid that? lat and lon must be in quotes. How to force that animation is not string?

Edit: I want to achieve that (using Twig and json_encode) - google.maps.Animation.DROP and this should be without quotes:

var l = {{ l|json_encode|raw }};
$(function() {
      new Maplace({
        show_markers: true,
        locations: [l],

    }).Load();
5
  • Why shouldn't it have quotes? What are you trying to achieve. Commented Dec 12, 2014 at 17:53
  • Maybe because it's a string?! Commented Dec 12, 2014 at 17:53
  • The string doesn't ACTUALLY have quotes around it (if you echo it you'll see that), it just displays that way in a var dump because it's a string. Commented Dec 12, 2014 at 17:54
  • All strings are put in quotes when var_dumped. Commented Dec 12, 2014 at 17:54
  • 1
    This question appears to be off-topic because the question is based on a misunderstanding of the output. Commented Dec 12, 2014 at 17:56

2 Answers 2

1

You can't pass a javascript object reference that way in json since json has to be string.

My suggestion would be to just pass the string "DROP" and then in javascript use [] object notation.

var animation =  google.maps.Animation[ myData.animation];

This would be the equivalent to:

var animation =  google.maps.Animation[ "DROP"];
Sign up to request clarification or add additional context in comments.

Comments

0

You can still do it server side, just loop for the array and cast the animation field from string to decimal, then use the edited array instead of the one you directly receive from the database .

To convert a type from string to float in php you can use : floatval function , details can be found here :
http://php.net/manual/en/function.floatval.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.