chielsen Posted September 19, 2007 Share Posted September 19, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/69970-json_encode-how-have-have-a-function-as-value/ Share on other sites More sharing options...
fanfavorite Posted September 19, 2007 Share Posted September 19, 2007 Will it not work without the quotes? json_encode(array('key' => Math.round(15))); Or just do it like this: $mathround = Math.round(15); json_encode(array('key' => $mathround)); Quote Link to comment https://forums.phpfreaks.com/topic/69970-json_encode-how-have-have-a-function-as-value/#findComment-351437 Share on other sites More sharing options...
chielsen Posted September 19, 2007 Author Share Posted September 19, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/69970-json_encode-how-have-have-a-function-as-value/#findComment-351442 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.