doumouyi4039 2016-01-01 19:47
浏览 104
已采纳

php数组具有相同的键,在一个数组中合并和重新排列键

I has array when i use var_dump function to print array show me the below result

var_dump($val);

the result is

array (size=1)
0 => string '6' (length=1)

array (size=1)
0 => string '6' (length=1)

array (size=1)
0 => string '4' (length=1)

as see the $val contains three different array that have the zero index key

how i can merge them in one array and change or rearrange the zero index to 0, 1 and 2

EDITED

for more information when i use print_r($val) the result as below

Array ( [0] => 6 ) Array ( [0] => 6 ) Array ( [0] => 4 )

but the number of array in $val various not every time ins three arrays would be 4 array or 5 array etc..

how i can merge all in one array and index of them?

  • 写回答

3条回答 默认 最新

  • dpnru86024 2016-01-01 19:56
    关注

    I believe you have an array like this,

    $val = array(
        0 => array("6"),
        1 => array("6"),
        2 => array("4")
    );
    

    So to merge the array elements and rearrange the indices, you can do something like this:

    foreach($val as $key => $array){
        $val[$key] = $array[0];
    }
    
    var_dump($val);
    

    Output:

    array (size=3)
      0 => string '6' (length=1)
      1 => string '6' (length=1)
      2 => string '4' (length=1)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类