tp5 saveAll() 修改 增加(有id就修改无id就增加)

  1. 当数组$data没有id时
array(2) {
  [0] => array(2) {
    ["name"] => string(6) "小王"
    ["sex"] => string(3) "男"
  }
  [1] => array(2) {
    ["name"] => string(6) "小红"
    ["sex"] => string(3) "女"
  }
}

->saveAll($data);此时为增加

  1. 当数组$data有id时
array(2) {
  [0] => array(3) {
    ["id"] => int(1)
    ["name"] => string(6) "小王"
    ["sex"] => string(3) "男"
  }
  [1] => array(3) {
    ["id"] => int(2)
    ["name"] => string(6) "小红"
    ["sex"] => string(3) "女"
  }
}

->saveAll($data);此时为修改

  1. 当数组$data有id也无id时
array(2) {
  [0] => array(2) {
    ["name"] => string(6) "小王"
    ["sex"] => string(3) "男"
  }
  [1] => array(3) {
    ["id"] => int(2)
    ["name"] => string(6) "小红"
    ["sex"] => string(3) "女"
  }
}

->saveAll($data);此时小王增加,小红修改

你可能感兴趣的:(php,thinkphp5)