public function ko(){ $arr_1 = [
['name' => 'zhang0','sex' => ],
['name' => 'zhang1','sex' => ],
['name' => 'zhang2','sex' => ],
['name' => 'zhang3','sex' => ],
['name' => 'zhang4','sex' => ]
]; $arr_2 = [
['name' => 'li0','sex' => ],
['name' => 'li1','sex' => ],
['name' => 'li2','sex' => ],
['name' => 'li4','sex' => ]
]; foreach ($arr_1 as &$v){
$v['sex_str'] = '男';
} $result = $arr_1;
foreach ($arr_2 as $v){
$v['sex_str'] = '女';
} dump($arr_1);
dump($arr_2);
dump($result);
exit;
}
<pre>array(5) {
[0] => array(3) {
["name"] => string(6) "zhang0"
["sex"] => int(0)
["sex_str"] => string(3) "男"
}
[1] => array(3) {
["name"] => string(6) "zhang1"
["sex"] => int(1)
["sex_str"] => string(3) "男"
}
[2] => array(3) {
["name"] => string(6) "zhang2"
["sex"] => int(0)
["sex_str"] => string(3) "男"
}
[3] => array(3) {
["name"] => string(6) "zhang3"
["sex"] => int(1)
["sex_str"] => string(3) "男"
}
[4] => &array(3) {
["name"] => string(3) "li4"
["sex"] => int(0)
["sex_str"] => string(3) "女"
}
}
</pre><pre>array(4) {
[0] => array(2) {
["name"] => string(3) "li0"
["sex"] => int(0)
}
[1] => array(2) {
["name"] => string(3) "li1"
["sex"] => int(1)
}
[2] => array(2) {
["name"] => string(3) "li2"
["sex"] => int(0)
}
[3] => array(2) {
["name"] => string(3) "li4"
["sex"] => int(0)
}
}
</pre><pre>array(5) {
[0] => array(3) {
["name"] => string(6) "zhang0"
["sex"] => int(0)
["sex_str"] => string(3) "男"
}
[1] => array(3) {
["name"] => string(6) "zhang1"
["sex"] => int(1)
["sex_str"] => string(3) "男"
}
[2] => array(3) {
["name"] => string(6) "zhang2"
["sex"] => int(0)
["sex_str"] => string(3) "男"
}
[3] => array(3) {
["name"] => string(6) "zhang3"
["sex"] => int(1)
["sex_str"] => string(3) "男"
}
[4] => &array(3) {
["name"] => string(3) "li4"
["sex"] => int(0)
["sex_str"] => string(3) "女"
}
}
</pre>