当前位置: 代码迷 >> PHP >> 数组资料操作
  详细解决方案

数组资料操作

热度:162   发布时间:2013-09-07 14:12:44.0
数组文件操作
本帖最后由 lazygc520 于 2013-09-05 13:13:44 编辑
已知数组a和数组b

$a = array (
 0 => 
  array (
    'cust_no' => '310F6 1VA5A',
    'lotno' => '2X15',
    'count' => '0',
  ),
  1 => 
  array (
    'cust_no' => '310F6 1VA5A',
    'lotno' => '2Z15',
    'count' => '16',
  ),
);

$b = array (
  0 => 
  array (
    'cust_no' => '310F6 1VA5A',
    'lotno' => '2X15',
    'count' => '0',
  ),
  1 => 
  array (
    'cust_no' => '310F6 1VA5A',
    'lotno' => '2Z15',
    'count' => '32',
  ),
  2 => 
  array (
    'cust_no' => '310F6 1VA5A',
    'lotno' => '3528',
    'count' => '80',
  ),
);


想要得到的结果是当数组b和数组a的cust_no和lotno都相同时,则提示update table sql
否则insert table sql。请问怎么求?

------解决方案--------------------
要什么条件自己改
foreach($b as $i=>$v) {
  print_r($v);
  if(isset($a[$i]) && $v['cust_no'] == $a[$i]['cust_no'] && $v['lotno'] == $a[$i]['lotno']) {
     echo "update table sql\n";
  }else echo "insert table sql\n";
}
  相关解决方案