Recursive PHP array to Javascript array/object

Veridis

New Member
Messages
16
Reaction score
0
Points
0
Hello Everyone,

I was wondering if you know anything about how to turn a recursive php array into a recursive javascript array, I've tried json_encode but it turns the references into null values and I need to keep the references.


Examples

Original php array:

PHP:
$test = array(
	'prop1' => array(
		'prop1a' => '',
		'prop1b' => 'string1b'
	), 
	'prop2' => array(
		'prop2a' => '',
		'prop2b' => 'string2b'
	)
);

$test['prop1']['prop1a'] = &$test['prop2'];
$test['prop2']['prop2a'] = &$test['prop1'];


array/object created by json_encode:

Code:
test = {
    "prop1":{
        "prop1a":null,
        "prop1b":"string1b"
    },
    "prop2":{
        "prop2a":null,
        "prop2b":"string2b"
    }
};


What I need:

Code:
test = {
    "prop1":{
        "prop1a": test.prop2,
        "prop1b": 'string1b'
    }, 
    "prop2":{
        "prop2a": test.prop1,
        "prop2b": 'string2b'
    }
}
 
Last edited:
Top