编程之美一题

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>

<body>
<?php
$arr = array(
array(1, 4, 7),
array(2, 5, 8),
array(3, 6, 9),
);
foreach ($arr[0] as $value1) {
	foreach ($arr[1] as $value2) {
		echo 'A = '.$value1.', B = '.$value2.'      '.'A = '.$value2.', B = '.$value1.'<br>';
		foreach ($arr[2] as $value3) {
			echo 'A = '.$value1.', B = '.$value3.'      '.'A = '.$value3.', B = '.$value1.'<br>'
			.'A = '.$value2.', B = '.$value3.'      '.'A = '.$value3.', B = '.$value2.'<br>';
		}
	}
}

echo '<br><br><br><br><br>2';

foreach ($arr[0] as $value1) {
	foreach ($arr[1] as $value2) {
		echo 'A = '.$value1.', B = '.$value2.'      '.'A = '.$value2.', B = '.$value1.'<br>';
	}
    foreach ($arr[2] as $value3) {
			echo 'A = '.$value1.', B = '.$value3.'      '.'A = '.$value3.', B = '.$value1.'<br>'
			.'A = '.$value2.', B = '.$value3.'      '.'A = '.$value3.', B = '.$value2.'<br>';
	}
}
foreach ($arr[1] as $value2) {
		foreach ($arr[2] as $value3) {
			echo 'A = '.$value2.', B = '.$value3.'      '.'A = '.$value3.', B = '.$value2.'<br>';
	}
}
echo '<br><br><br><br><br>3';

foreach ($arr[0] as $arr[0][3]) {
	foreach ($arr[1] as $value2) {
		echo 'A = '.$arr[0][3].', B = '.$value2.'      '.'A = '.$value2.', B = '.$arr[0][3].'<br>';
	}
    foreach ($arr[2] as $arr[2][3]) {
			echo 'A = '.$arr[0][3].', B = '.$arr[2][3].'      '.'A = '.$arr[2][3].', B = '.$arr[0][3].'<br>';
	}
}
foreach ($arr[1] as $arr[1][3]) {
		foreach ($arr[2] as $arr[2][3]) {
		echo 'A = '.$arr[1][3].', B = '.$arr[2][3].'      '.'A = '.$arr[2][3].', B = '.$arr[1][3].'<br>';
	}
}
?>
</body>
</html>

    原文作者:iastro
    原文地址: https://blog.csdn.net/iastro/article/details/45093927
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞