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);
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题