dongying3744 2019-01-08 14:55
浏览 27
已采纳

将动态数组与动态键组合到单个数组中

I have this dynamic multiple arrays that I need to combine in one array and serialized them. The problem is I need to keep both key and value.

$arr = array($bet_option_id => $bet_option_name);

Here i need to keep both bet_option_id AND bet_option_name. Then this result output:

Array ( [997650802] => Over 2.5 ) 
Array ( [997650807] => Yes )

This need to be simply

Array
(
  [997650802] => Over 2.5
  [997650807] => Yes
)

As it's dynamic, sometimes not comes with just single array so apparently I couldn't get it working. I need to retrieve both bet_option_id & bet_option_name. Tried something like this:

 $arr = array($bet_option_id => $bet_option_name); //This is where all array keys, values are stores
 $result = array();
 foreach ($arr as $array) {
     $result = array_merge($result, $array);
  } 

Any inputs will be nice.

  • 写回答

2条回答 默认 最新

  • douyi7055 2019-01-08 15:11
    关注

    Rather than create individual arrays like...

    $arr = array($bet_option_id => $bet_option_name);
    

    If you first create an empty array ( like you do with $result)

    $arr = array();
    

    and then add each item in using

    $arr[$bet_option_id] = $bet_option_name;
    

    Then you don't need to manipulate the array after - just create it as you want it in the first place.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计