开发者社区> 问答> 正文

php 数组合并的问题? 400 报错

php 数组合并的问题? 400 报错

先谢谢各位了

已知

$arr1 = array("1月","3月","4月");
$arr1date=array("100","200","300");

$arr2 = array("1月","2月","5月");
$arr2date=array("300","400","500");


$arr3 =array("1月","2月","3月","4月","5月");


$arr1date1=array("100","0","200","300","0");

$arr2date1=array("300","400","0","0","500");


展开
收起
爱吃鱼的程序员 2020-06-03 16:15:31 436 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
    <?php
    $arr1 = array("1月","3月","4月");
    $arr1date=array("100","200","300");
    
    $arr2 = array("1月","2月","5月");
    $arr2date=array("300","400","500");
    
    $arr3 =array("1月","2月","3月","4月","5月");
    
    $a1 = array_combine($arr1,$arr1date);
    $a2 = array_combine($arr2,$arr2date);
    $arr1date1 = $arr1date2 =array();
    
    foreach ($arr3 as $v){
    	if(isset($a1[$v])){
    		$arr1date1[] = $a1[$v];
    	}else{
    		$arr1date1[] = "0";
    	}
    	if(isset($a2[$v])){
    		$arr2date1[] = $a2[$v];
    	}else{
    		$arr2date1[] = "0";
    	}
    
    }
    print_r($arr1date1);
    print_r($arr2date1);
    ?>



    ######太牛了,感谢
    2020-06-03 17:32:59
    赞同 展开评论 打赏
问答分类:
PHP
问答地址:
相关产品:
问答排行榜
最热
最新

相关电子书

更多
PHP安全开发:从白帽角度做安全 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载
复杂PHP系统性能瓶颈排查及优化 立即下载