I get and error array to string conversion error on line 11 I need to compare $result array with $file array and then over write FILE with $result data. In other words, FILE and the data it contains is continuously being updated with $result
compare -> overwrite -> repeat at next execution.
Note: .db file is empty at first cycle but becomes populated at first write.
sample code with Array to string conversion error:
<?php
$id = $argv[1]; //variable for inbound
$result = array(
'return' => array(
array(1,2,3),
array(6,2,3),
array(3,2,3),
)
);
function getdiff($new, $old) {
$diff = array_intersect($new, $old);
return $diff;
}
$old = file_exists('1.db') ? json_decode(file_get_contents('1.db'), 1) : array();
$arrayDiffresult = getdiff( $result, $old);
file_put_contents('1.db', json_encode($result));
print_r(
getdiff($result, $old)
);
?>
I have a second method I have tried and I get the same error, at the comparison point line 9.
$result = array(
'return' => array(
array(1,2,3),
array(5,2,3),
array(3,2,3),
)
);
$lines = file("myDB.db");
$arrayDiffresult = array_diff ( $result['return'], $lines);
file_put_contents('myDB.db', print_r($result['return'], true));