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

...
duanhuai7532
duanhuai7532 请参阅上述问题中的示例。顺便说一句:我可以在评论中发布代码吗?
一年多之前 回复
dtcuv8044
dtcuv8044 尝试做一个var_dump($arrayFloat,$arrayString);并查看这些值是否为数组。
一年多之前 回复
duanji8887
duanji8887 提供两个数组的样本,如上面的注释中所述
一年多之前 回复
dqsvf28682
dqsvf28682 $arrayFloat和$arrayString包含什么?尝试在合并之前转储它们
一年多之前 回复

1个回答



你可以这样做,</ p>

  $ arrayFloat = json_decode(json_encode(  $ arrayFloat),TRUE);  //刷新任何对象依赖项以执行数组操作
$ arrayString = json_decode(json_encode($ arrayString),true);

$ new = array_merge($ arrayFloat,$ arrayString);
print_r($ new); \ n </ code> </ pre>
</ div>

展开原文

原文

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);

douzang7928
douzang7928 如何获得什么价值?
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐