& 引用传值

    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] =&gt; array(3) {
[&quot;name&quot;] =&gt; string(6) &quot;zhang0&quot;
[&quot;sex&quot;] =&gt; int(0)
[&quot;sex_str&quot;] =&gt; string(3) &quot;男&quot;
}
[1] =&gt; array(3) {
[&quot;name&quot;] =&gt; string(6) &quot;zhang1&quot;
[&quot;sex&quot;] =&gt; int(1)
[&quot;sex_str&quot;] =&gt; string(3) &quot;男&quot;
}
[2] =&gt; array(3) {
[&quot;name&quot;] =&gt; string(6) &quot;zhang2&quot;
[&quot;sex&quot;] =&gt; int(0)
[&quot;sex_str&quot;] =&gt; string(3) &quot;男&quot;
}
[3] =&gt; array(3) {
[&quot;name&quot;] =&gt; string(6) &quot;zhang3&quot;
[&quot;sex&quot;] =&gt; int(1)
[&quot;sex_str&quot;] =&gt; string(3) &quot;男&quot;
}
[4] =&gt; &amp;array(3) {
[&quot;name&quot;] =&gt; string(3) &quot;li4&quot;
[&quot;sex&quot;] =&gt; int(0)
[&quot;sex_str&quot;] =&gt; string(3) &quot;女&quot;
}
}
</pre><pre>array(4) {
[0] =&gt; array(2) {
[&quot;name&quot;] =&gt; string(3) &quot;li0&quot;
[&quot;sex&quot;] =&gt; int(0)
}
[1] =&gt; array(2) {
[&quot;name&quot;] =&gt; string(3) &quot;li1&quot;
[&quot;sex&quot;] =&gt; int(1)
}
[2] =&gt; array(2) {
[&quot;name&quot;] =&gt; string(3) &quot;li2&quot;
[&quot;sex&quot;] =&gt; int(0)
}
[3] =&gt; array(2) {
[&quot;name&quot;] =&gt; string(3) &quot;li4&quot;
[&quot;sex&quot;] =&gt; int(0)
}
}
</pre><pre>array(5) {
[0] =&gt; array(3) {
[&quot;name&quot;] =&gt; string(6) &quot;zhang0&quot;
[&quot;sex&quot;] =&gt; int(0)
[&quot;sex_str&quot;] =&gt; string(3) &quot;男&quot;
}
[1] =&gt; array(3) {
[&quot;name&quot;] =&gt; string(6) &quot;zhang1&quot;
[&quot;sex&quot;] =&gt; int(1)
[&quot;sex_str&quot;] =&gt; string(3) &quot;男&quot;
}
[2] =&gt; array(3) {
[&quot;name&quot;] =&gt; string(6) &quot;zhang2&quot;
[&quot;sex&quot;] =&gt; int(0)
[&quot;sex_str&quot;] =&gt; string(3) &quot;男&quot;
}
[3] =&gt; array(3) {
[&quot;name&quot;] =&gt; string(6) &quot;zhang3&quot;
[&quot;sex&quot;] =&gt; int(1)
[&quot;sex_str&quot;] =&gt; string(3) &quot;男&quot;
}
[4] =&gt; &amp;array(3) {
[&quot;name&quot;] =&gt; string(3) &quot;li4&quot;
[&quot;sex&quot;] =&gt; int(0)
[&quot;sex_str&quot;] =&gt; string(3) &quot;女&quot;
}
}
</pre>

 
上一篇:TOP100summit:【分享实录-QQ空间】10亿级直播背后的技术优化


下一篇:Flex 弹性盒模型