doutan5724 2019-04-04 07:30
浏览 103
已采纳

array_merge的问题

I have two models each returning an array (provided by the ERP system). Now I want to merge these arrays and all I have the parameters and values ​​in one array.

The problem is that the $new array is empty. The 'Parameters' was an string (e.g. 'cost_all'), an die 'Value' is an float or an string.

$new =  [];
$arrayFloat = ArrayHelper::map(ParameterFloat::findAll($this->id), 'Parameter', 'Value');        
$arrayString = ArrayHelper::map(ParameterString::findAll($this->id), 'Parameter', 'Value');

$new = array_merge($arrayFloat, $arrayString);

$arrayFloat = 
array(681) (
  [005001000000nr_rrr_idnr] => (float) -1
  [005001000000nr_rrr_kdnr] => (float) -1
  [005001000000nr_rrra_kdnr] => (float) -1
  [005001000000nr_rrrb_kdnr] => (float) -1

...

$arrayString = 
array(436) (
  [005001000000algos] => (string) none
  [005002000000algos] => (string) none
  [005003000000algos] => (string)
  [005004000000algos] => (string) lx325
  [006580000000algos] => (string) lx345

...
  • 写回答

1条回答

  • dqrdlqpo775594 2019-04-04 08:01
    关注

    You can do something like this,

    $arrayFloat = json_decode(json_encode($arrayFloat),true); // flushes any object dependancies to perform array operations
    $arrayString = json_decode(json_encode($arrayString),true);
    
    $new = array_merge($arrayFloat, $arrayString);
    print_r($new);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮