All pastes #344944 Raw Edit

Untitled

public text v1 · immutable
·published 2007-02-08 03:35 UTC
rendered paste body
<?php

// this assumes that each "Layout" can have one "Multi" and each "Multi" has one "Layout" and optionally another "Multi"

$source = array(
	'Layout' => 1,
	'Multi' => array(
		'Layout' => 2,
		'Multi' => array(
			'Layout' => 3,
			'Multi' => array(
				'Layout' => 4,
				'Multi' => array(
					'Layout' => 6,
					'Multi' => array(
						'Layout' => 7
					)
				)
			)
		)
	)
);

function descend($data, &$fixed)
{
	$fixed[] = array('Layout' => $data['Layout']);
	if (isset($data['Multi'])) {
		descend($data['Multi'], &$fixed);
	}
}
$fixed = array();
descend($source, &$fixed);

print_r($fixed);

?>