& 引用传值

    public function ko(){

        $arr_1 = [
            ['name' => 'zhang0','sex' =>   0],
            ['name' => 'zhang1','sex' =>   1],
            ['name' => 'zhang2','sex' =>   0],
            ['name' => 'zhang3','sex' =>   1],
            ['name' => 'zhang4','sex' =>   0]
        ];

        $arr_2 = [
            ['name' => 'li0','sex' =>   0],
            ['name' => 'li1','sex' =>   1],
            ['name' => 'li2','sex' =>   0],
            ['name' => 'li4','sex' =>   0]
        ];

        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>

 

 

转载于:https://www.cnblogs.com/pansidong/p/10752757.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值