Consistent persistence, PHP's better solution to data update

autoload
Release: 2023-04-09 20:32:01
Original
2157 people have browsed it

Consistent persistence, PHPs better solution to data update

1. Mainly used function array_diff_assoc()

a. Syntax:

array_diff_assoc(array1,array2,array3...);
Copy after login
  • 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);
?>
Copy after login

c. Output:

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

2 .Actual usage during website development

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

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!