i have an object in this format that can be infinately deep.
stdClass Object
(
[condition] => AND
[rules] => Array
(
[0] => stdClass Object
(
[id] => app
[field] => app
[type] => string
[operator] => equal
[value] => files_sharing
)
[1] => stdClass Object
(
[id] => deviceType
[field] => deviceType
[type] => string
[input] => select
[operator] => equal
[value] => android
)
[2] => stdClass Object
(
[id] => userGroup
[field] => userGroup
[type] => string
[operator] => equal
[value] => admin
)
[3] => stdClass Object
(
[condition] => AND
[rules] => Array
(
[0] => stdClass Object
(
[id] => userGroup
[field] => userGroup
[type] => string
[operator] => equal
[value] => group
)
[1] => stdClass Object
(
[id] => time
[field] => time
[type] => time
[input] => text
[operator] => between
[value] => Array
(
[0] => 12:30 am -0500
[1] => 06:00 am -0500
)
)
[2] => stdClass Object
(
[id] => request
[field] => request
[type] => string
[input] => select
[operator] => equal
[value] => post
)
)
)
)
)
The format im trying to get it into is
array(
0 => array(
'condition' => 'and',
'rules' => array({RULESHERE})
),
1 => array(
'condition' => 'and',
'rules' => array({RULES HERE})
),
);
What i have at the moment is this but it is failing hardcore.
Public function loop(obj) {
// First we get the condition
$this->stack[$this->stackCounter]['condition'] = $obj->condition;
$this->stack[$this->stackCounter]['rules'] = array();
foreach ($obj as $rule) {
if (isset($rule->condition)) {
$this->loop($rule);
} else {
array_push($this->stack[$this->stackCounter]['rules'], $rule);
// $this->evalCondition($rule);
}
}
$this->stackCounter++;
}
}
Could someone please lend an idiot a hand.