0

I did a function that generates from a php array a javascript object, for instance

$this->routes = array(
        'Module' => array(
            'Route1' => $renderer->url('route1', array('lang' => $lang_short)),
            'Route2' => $renderer->url('route1', array('lang' => $lang_short)),
        )
    );

My function will generate a javascript object like

{Static: {Module: {Route1: 'route1', Route2: 'route2'}}}

So I can access this in js like

Static.Module.Route1

The "problem" is the method I made handles arrays just with 2 nested arrays, not more. What would be a nice and easy way to achieve this?

1
  • 2
    Change your method to handle n nested arrays? I really don't know what you want from us... Commented Sep 10, 2014 at 21:10

1 Answer 1

4

Use the native json_encode function, instead of your custom function.

Sign up to request clarification or add additional context in comments.

1 Comment

you'r totally right, I guess I did not think about this as I wanted to write my own. thanks

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.