duandanxiu6965 2014-11-14 07:56
浏览 80

数组到字符串转换错误行11

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));
  • 写回答

1条回答 默认 最新

  • dongmen1925 2014-11-14 08:10
    关注

    I believe array_intersect is only used in one dimensional arrays, and it is attempting to treat the nested arrays as a string for equality comparison. However looking at the documentation show the function array_uintersect where you can write your own comparison function as a callback. You didn't provide much information as to what the requirements are but if you do I'd be happy to help

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?