私の問題は私が望む構造体に配列を配置することはできません。 array1とarray2は動的に生成されます。配列2で見ることができるように、配列1で同じsubjectidを持っています。つまり、要素cpe 305の下にあることを意味します。配列5のidが5のすべての要素は、cpe配列をPHPで配列
Array
(
[0] => Array
(
[subjectid] => 5
[subjectcode] => Cpe 305
)
[1] => Array
(
[subjectid] => 4
[subjectcode] => Cpe 304
)
)
配列2:
Array
(
[0] => Array
(
[subjectid] => 5
[soid] => 1
[socode] => A
[sodesc] => Ability to apply knowledge of mathematics and science to solve engineering problems
)
[1] => Array
(
[subjectid] => 5
[soid] => 3
[socode] => C
[sodesc] => Ability to design a system, component, or process to meet the desired needs within realistic constraints such as economic, environmental, social, political, ethical, health and safety, manufacturability, and sustainability, in accordance to standards
)
[2] => Array
(
[subjectid] => 5
[soid] => 4
[socode] => D
[sodesc] => Ability to function on multidisciplinary teams
)
[3] => Array
(
[subjectid] => 5
[soid] => 5
[socode] => E
[sodesc] => Ability to identify, formulate, and solve engineering problems
)
[4] => Array
(
[subjectid] => 5
[soid] => 9
[socode] => I
[sodesc] => Recognition of the need for, and an ability to engage in life-long learning
)
[5] => Array
(
[subjectid] => 4
[soid] => 10
[socode] => J
[sodesc] => Knowledge of contemporary issues
)
)
0 CPE 304配列1と305と同じ論理私は
これを試してみた何
OUTPUT(私の所望の構造)
Array(
[subjectid] => 5
[subjectcode] => Cpe 305
[sodetails] => array(
[0]=>Array ([soid]=>1
[socode]=>A)
[1]=>Array([soid]=>3
[socode]=>C .....until the last
)
[subjectid] => 4
[subjectcode] => Cpe 305
[sodetails] => array(
[0]=>Array ([soid]=>10
[socode]=>J)
.......until the last
)
はコードイムテストです。私はテストコードの中にわずかなデータしか入れていません。代わりにm x n
回ループ/反復処理を実行しているの
$so = array();
$exist = array();
foreach ($this->subject as $key => $value) {
foreach ($this->sodetails as $key2 => $value2) {
if($value['subjectid'] === $value2['subjectid']){
$exist = array(
"subjectid" => $value['subjectid'],
"details" =>array(
"soid" => $value2['soid']
)
);
array_push($so, $exist);
}
}
}
コードを書きましたか?この問題を解決するための私たちの努力を示す – rokas
あなたの試行を見せてください。 – take