I want to reassemble the following array for each management_code, class_type.
$varArrayA = array( array( "manegement_code" => "1", "class_type" => array('A','B','C') ), array( "manegement_code" => "2", "class_type" => array('A','B','C') ), array( "manegement_code" => "3", "class_type" => array('A','B','C') ) ); $varArrayB = array( array( "manegement_code" => "1", "class_type" => "A", "price" => "200" ), array( "manegement_code" => "1", "class_type" => "B", "price" => "300" ), array( "manegement_code" => "1", "class_type" => "B", "price" => "300" ), array( "manegement_code" => "2", "class_type" => "B", "price" => "300" ) );
*I want this result
$varArrayB = array( array( "manegement_code" => "1", "class_type" => "A", "price" => "200" ), array( "manegement_code" => "1", "class_type" => "B", "price" => "600" ), array( "manegement_code" => "2", "class_type" => "B", "price" => "300" ) );
I made it as follows
I'm confused about incorporating conditions in class_type.
I would appreciate it if you could be a professor.
foreach ($varArrayA as $i => $varValueA) { foreach ($varArrayB as $rowow ){ if($rowow['manegement_code']==$varValueA['manegement_code']){ $varArrayC[$i]['manegement_code'] = $rowow['manegement_code']; $varArrayC[$i]['class_type'] = $rowow['class_type']; $num = $num+$rowow['price']; $varArrayC[$i]['price'] = $num; } } }
過去2質問 日本語で質問しているのになぜ急に英語?
ただ、いずれも回答ついている質問を解決するところからすべきでは。放置はいけません。