我有一个应该比较 2 个数组的函数。Array diff 正在发送警告,即第一个参数不是数组......也可以使用任何更好的方法来编写此函数。我只是想在这个上做点什么。谢谢!
function changeLog(){
include('../includes/conn.inc.php');
//select object and make an array with each current value
$stmt = $mysql->prepare ("SELECT * FROM table WHERE id=?");
$stmt->bind_param("i", $_POST['id']);
$OK = $stmt->execute();
$stmt->bind_result(
$id,
$name,
$created,
$edited,
$owner
);
while($row = $stmt->fetch()) {
$array1 = array(
'name' => $name,
'owner' => $owner
);}
$stmt->close();
//$array1 now holds current values for each field
//now grab the post values from the update and stick them into array2
$name= $_POST['name'];
$owner= $owner;
$array2 = array(
'name' => $name,
'owner' => $owner
);
//$array2 now holds post values for each field in the update
//check the arrays and spit out the differences
$result = array_diff($array1, $array2);
//strip the values and just output the array keys
$dbInput =(array_keys($result));
foreach($dbInput as $i){
$owner= 'use'.$_SESSION['i'];
$sql = 'INSERT INTO history (id, created, edited, owner, parent, body)
VALUES (NULL,NOW(),NOW(),?,?,?)';
$stmt = $mysql->stmt_init();
if ($stmt->prepare($sql)) {
$stmt->bind_param('sss', $owner, $_POST['id'], $i);
$OK = $stmt->execute();}
$stmt->close();
}
}// end changeLog