有4个数组,以数据最多的数组为基础,根据前后相关的KEY值合并成一个二维数组

adophper 发布于 2014/08/16 23:14
阅读 275
收藏 1
PHP

有4个数组,以数据最多的数组为基础,根据前后相关的KEY值合并成一个二维数组,并且每条数据都要包含先前4个数组的id,title

<?php

$arr_1 = array(
	array(
		'courseid' => 540000,
		'coursetitle' => 'Advanced Algebra/Precalculus',
		'yearnumber' => 1
		'prerequisite' => ''
	)
);

$arr_2 = array(
	array(
		'courseid' => 586000,
		'coursetitle' => 'Algebra II/Trigonometry',
		'yearnumber' => 2
		'prerequisite' => '540000'
	),
	array(
		'courseid' => 593000,
		'coursetitle' => 'Geometry Honors',
		'yearnumber' => 2
		'prerequisite' => '540000'
	),
	array(
		'courseid' => 593000,
		'coursetitle' => 'Geometry',
		'yearnumber' => 2
		'prerequisite' => '584000'
	)
);

$arr_3 = array(
	array(
		'courseid' => 591000,
		'coursetitle' => 'Mathematical Analysis',
		'yearnumber' => 3
		'prerequisite' => '586000'
	),
	array(
		'courseid' => 59600,
		'coursetitle' => 'Computer Mathematics',
		'yearnumber' => 3
		'prerequisite' => '593000'
	)
);

$arr_4 = array(
	array(
		'courseid' => 581000,
		'coursetitle' => 'Calculus BC - AP',
		'yearnumber' => 4
		'prerequisite' => '591000'
	),
	array(
		'courseid' => 571000,
		'coursetitle' => 'Algebra II/Trigonometry',
		'yearnumber' => 4
		'prerequisite' => '591000'
	),
	array(
		'courseid' => 583000,
		'coursetitle' => 'Calculus AB - AP',
		'yearnumber' => 4
		'prerequisite' => '596000'
	),
	array(
		'courseid' => 586100,
		'coursetitle' => 'Advanced Algebra/Precalculus',
		'yearnumber' => 4
		'prerequisite' => '596000'
	)
);



要将4个数组组合在多行数据,并且每行数据不重复,每个数组的长度不固定都是MYSQL中查询出来。

求解决方法,用count来比较然后一个一个数组插入新的一个数组?


加载中
0
inuxor
inuxor
这题目没看懂
返回顶部
顶部