Home >Backend Development >PHP Tutorial >Consistent persistence, PHP's better solution to data update

Consistent persistence, PHP's better solution to data update

autoload
autoloadOriginal
2021-03-25 11:19:372223browse

Consistent persistence, PHPs better solution to data update

1. Mainly used function array_diff_assoc()

a. Syntax:

array_diff_assoc(array1,array2,array3...);
  • array1 The first array to compare with other arrays. (Required)

  • array2 The array to compare to the first array. (required)

  • array3,... The other array to compare with the first array. (Optional)

array_diff_assoc() The function is used to compare the key names and key values ​​of two (or more) arrays and return the difference set. This function compares the keys and values ​​of two (or more) arrays and returns a difference array that includes all elements in the compared array (array1) that are not in any of the other argument arrays (array2 or array3 etc.) in the key name and key value.

b. Example:

<?php
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "green", "yellow", "red");
$result = array_diff_assoc($array1, $array2);
print_r($result);
?>

c. Output:

Array
(
    [b] => brown
    [c] => blue
    [0] => red
)

2 .Actual usage during website development

//对表单数据进行接受
  $id = (int)$_POST[&#39;id&#39;];
//通过$id查询相应数据
  $art[]=.............
//通过表单  
  $data[]=..................
//数据比较
$data = array_diff_assoc($data,$art);

//判定
if(!$data){
   //输出无更新
}else{
  //进行更新操作
}

Recommended: "php video tutorial""php tutorial"

The above is the detailed content of Consistent persistence, PHP's better solution to data update. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn