$A = array( '1' => array( 'amount' => '100', 'amount1' =>'50', 'amount2' => '200', 'payment' => '12121212', 'payment1' => '12121212' ), '2' => array( 'amount' => '10', 'amount1' =>'5', 'amount2' => '20', 'payment' => '45454545', 'payment1' => '45454545' ) ); $B = array( '1' => array( 'user_money' => '100', 'user_money1' =>'50', 'user_money2' => '200' ), '2' => array( 'user_money' => '10', 'user_money1' =>'5', 'user_money2' => '20', 'user_money3' => '45454545' ) ); foreach( $A as $k => $v){ foreach($B as $kk => $vv){ if($k = $kk){ $vvv[] = $v+$vv; } } } var_dump($vvv);
array (size=4) 0 => array (size=8) 'amount' => string '100' (length=3) 'amount1' => string '50' (length=2) 'amount2' => string '200' (length=3) 'payment' => string '12121212' (length=8) 'payment1' => string '12121212' (length=8) 'user_money' => string '100' (length=3) 'user_money1' => string '50' (length=2) 'user_money2' => string '200' (length=3) 1 => array (size=9) 'amount' => string '100' (length=3) 'amount1' => string '50' (length=2) 'amount2' => string '200' (length=3) 'payment' => string '12121212' (length=8) 'payment1' => string '12121212' (length=8) 'user_money' => string '10' (length=2) 'user_money1' => string '5' (length=1) 'user_money2' => string '20' (length=2) 'user_money3' => string '45454545' (length=8) 2 => array (size=8) 'amount' => string '10' (length=2) 'amount1' => string '5' (length=1) 'amount2' => string '20' (length=2) 'payment' => string '45454545' (length=8) 'payment1' => string '45454545' (length=8) 'user_money' => string '100' (length=3) 'user_money1' => string '50' (length=2) 'user_money2' => string '200' (length=3) 3 => array (size=9) 'amount' => string '10' (length=2) 'amount1' => string '5' (length=1) 'amount2' => string '20' (length=2) 'payment' => string '45454545' (length=8) 'payment1' => string '45454545' (length=8) 'user_money' => string '10' (length=2) 'user_money1' => string '5' (length=1) 'user_money2' => string '20' (length=2) 'user_money3' => string '45454545' (length=8)
$C = array( * '1' => array( 'user_money' => '100', 'user_money1' =>'50', 'user_money2' => '200' 'amount' => '100', 'amount1' =>'50', 'amount2' => '200', 'payment' => '12121212', 'payment1' => '12121212' ), '2' => array( 'user_money' => '10', 'user_money1' =>'5', 'user_money2' => '20', 'user_money3' => '45454545' 'amount' => '10', 'amount1' =>'5', 'amount2' => '20', 'payment' => '45454545', 'payment1' => '45454545' ) * );
私の名前はすべて同じであることを補足します。あとは作成した名前に従って値をマージします
$A = array( '1' => array( 'amount' => '100', 'amount1' =>'50', 'amount2' => '200', 'payment' => '12121212', 'payment1' => '12121212' ), '2' => array( 'amount' => '10', 'amount1' =>'5', 'amount2' => '20', 'payment' => '45454545', 'payment1' => '45454545' ) ); $B = array( '1' => array( 'user_money' => '100', 'user_money1' =>'50', 'user_money2' => '200' ), '2' => array( 'user_money' => '10', 'user_money1' =>'5', 'user_money2' => '20', 'user_money3' => '45454545' ) );foreach($A as $k=>$v) $r[] = $v + $B[$k];var_export($r);
array ( 0 => array ( 'amount' => '100', 'amount1' => '50', 'amount2' => '200', 'payment' => '12121212', 'payment1' => '12121212', 'user_money' => '100', 'user_money1' => '50', 'user_money2' => '200', ), 1 => array ( 'amount' => '10', 'amount1' => '5', 'amount2' => '20', 'payment' => '45454545', 'payment1' => '45454545', 'user_money' => '10', 'user_money1' => '5', 'user_money2' => '20', 'user_money3' => '45454545', ),)
$A = array( '1' => array( 'amount' => '100', 'amount1' =>'50', 'amount2' => '200', 'payment' => '12121212', 'payment1' => '12121212' ), '2' => array( 'amount' => '10', 'amount1' =>'5', 'amount2' => '20', 'payment' => '45454545', 'payment1' => '45454545' ) ); $B = array( '1' => array( 'user_money' => '100', 'user_money1' =>'50', 'user_money2' => '200' ), '2' => array( 'user_money' => '10', 'user_money1' =>'5', 'user_money2' => '20', 'user_money3' => '45454545' ) );foreach($A as $k=>$v) $r[] = $v + $B[$k];var_export($r);
array ( 0 => array ( 'amount' => '100', 'amount1' => '50', 'amount2' => '200', 'payment' => '12121212', 'payment1' => '12121212', 'user_money' => '100', 'user_money1' => '50', 'user_money2' => '200', ), 1 => array ( 'amount' => '10', 'amount1' => '5', 'amount2' => '20', 'payment' => '45454545', 'payment1' => '45454545', 'user_money' => '10', 'user_money1' => '5', 'user_money2' => '20', 'user_money3' => '45454545', ),)
array ( 16128 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16128', ), 16127 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16127', ), 16126 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16126', ), 16125 => array ( 'user_money' => '0.00', 'change_desc' => '订单 2016022647848 赠送的积分', 'user_id' => '16125', ), 16124 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16124', ), 16123 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16123', ), 16122 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16122', ), 16121 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16121', ), 16120 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16120', ), 16119 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16119', ), 16118 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16118', ), 16117 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16117', ), 16116 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16116', ), 16115 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16115', ), 16114 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16114', ), 16113 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16113', ), 16112 => array ( 'user_money' => '0.00', 'change_desc' => '注册送积分', 'user_id' => '16112', ), 16111 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16111', ), 16110 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16110', ), 16109 => array ( 'user_money' => '0.00', 'change_desc' => '', 'user_id' => '16109', ),)
違いはありますか?
キーストロークに関連付けられています
foreach($A as $k=>$v) $r[ $k] = $v + $B[$k]; でモデレータとしての私のニーズがわかります
users テーブルには user_name フィールドが 1 つだけ必要であり、
account_log にはchange_desc、user_money、およびfrozen_moneyが必要です。
user_account テーブルには支払いと金額が必要です。3 つのテーブルの関連フィールドは user_id です。
array ( 16127 => array ( 'amount' => '1000.00', 'payment' => '储值卡号:16011118067599', 'user_id' => '16127', ), 16110 => array ( 'amount' => '1000.00', 'payment' => '储值卡号:16011128883958', 'user_id' => '16110', ), 16102 => array ( 'amount' => '1000.00', 'payment' => '储值卡号:16011125271413', 'user_id' => '16102', ), 16077 => array ( 'amount' => '500.00', 'payment' => '储值卡号:16011138443550', 'user_id' => '16077', ), 16062 => array ( 'amount' => '5.00', 'payment' => '储值卡号:15122274342772', 'user_id' => '16062', ), 16048 => array ( 'amount' => '500.00', 'payment' => '储值卡号:16011149520320', 'user_id' => '16048', ), 16037 => array ( 'amount' => '1000.00', 'payment' => '储值卡号:16011133169060', 'user_id' => '16037', ), 16029 => array ( 'amount' => '500.00', 'payment' => '储值卡号:16011127482943', 'user_id' => '16029', ), 16006 => array ( 'amount' => '500.00', 'payment' => '储值卡号:16011188176126', 'user_id' => '16006', ),)
users表数据user_id user_name1 ss2 dd
account_log表数据 ==》记录所有的充值、消费、退款记录user_id user_money frozen_money change_desc1 10 0 充值1 20 0 充值1 -40 0 消费2 50 0 充值3 50 0 充值
' user_money' => '10' ,
' user_money' => '20' ,
'user_money' => '-40' 、
'payment' => 'リチャージ 10 カード番号 1232'、
'支払い' => 'リチャージ 20 カード番号 5345'
)、
このようになります不可能です 存在します
3 レベルの配列に変更できます
0 => array(
'user_money' =>array( '10', '20' , '-40 '),
'payment'=>array('リチャージ 10 カード番号 1232', 'リチャージ 20 カード番号 5345') //ここでの対応する user_money は 3 つの値である必要があります,
),
1 => ; array(
'user_id' => '2',
'user_money' => '50',
'payment'=>'リチャージ 50 カード番号 3453'
),
2=>array(
'user_id' => '3',
'user_money' => '50',
'payment'=>'リチャージ 50 カード番号 5585'
)
原則に従ってマージします
$a=array(
0 => array(
0 ', '20', '-40' ),
'支払い '=>array('リチャージ 10 カード番号 1232', 'リチャージ 20 カード番号 5345 ')//ここでの対応するuser_moneyは3つの値でなければなりません
1 => > '50'、
'支払い'=>'リチャージ 50 カード番号 5585'、
$b=array_merge_recursive($a[0],$a[1]);
$b=array_merge_recursive($b, $a[2]);
結果を取得
array(3) { [0]=> [1]=> 文字列(1) "2" => 文字列(1) "3" } ["user_money"]=> 文字列(2) "10" [1]=> 文字列(2) "20" => 文字列(3) "50" => 文字列(2) "50" } ["支払い"]=> array(4) { [0]=> string(18) "リチャージ 10 カード番号 1232" [1]=> string(18) "リチャージ 20カード番号 5345" [2]=> string(18) "リチャージ 50 カード番号 3453" [3]=> string(18) "リチャージ 50 カード番号 5585" } }