Jump to content

Json_encode - How have have a function as value


chielsen

Recommended Posts

I use json_encode to parse data which ill use with js on my site.

Now i want to have a function instead of a string/int.

Like this:

json_encode(array('key' => 'Math.round(15)'));

 

But now Math.round(15) is a string and not a function. How do i get this right?

Nope, if i do the first i get:

 

{"key":"Math15"}

 

Which makes sence because php thinks i want to use the dot operator on the constant Math (which doesn't exists, so php assumes the string 'Math') and the result of the round function which is 15 (round(15) is 15.

 

So i have a problem. Do i need to make my own function to get rid of the quotes?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.