[ create a new paste ] login | about

Link: http://codepad.org/hvi1b14B    [ raw code | output | fork ]

PHP, pasted on Jul 1:
<?php
$array = array(
	'1' => array(
		'name' => '勉強',
		'post' => 'は',
		'child' => array(
			'2' => array(
				'name' => '国語',
				'post' => 'で',
				'child' => array(
					'3' => array('name' => '読書'),
					'4' => array('name' => '作文'),
				),
			),
		),
	),
	'5' => array('name' => '遊び')
);

function search_name($arr, $name)
{
	foreach ($arr as $val) {
		if ($val["name"] == $name)
			return $name;
		if (array_key_exists("child", $val)) {
			$ret = search_name($val["child"], $name);
			if ($ret != "")
				return $val["name"] . $val["post"] . $ret;
		}
	}
	return "";
}

echo search_name($array, "読書");
?>


Output:
1
勉強は国語で読書


Create a new paste based on this one


Comments: