如何在新数组中存储数组值?

时间:2019-03-15 10:00:28

标签: php

我有这个数组

$array=(
   Array([0] => ENG)
   Array([0] => ENG)
   Array([0] => URDU)
   Array([0] => LIB)
   Array([0] => URD)
   Array([0] => ISL)
   Array([0] => PHY)
   Array([0] => ISL)
   Array([0] => SCI)
   Array([0] => MATH)
   Array([0] => CHEM)
);

我想获取这些值并存储在这样的新数组中

array(
[0]=>ENG 
[1]=>ENG 
[2]=>URDU 
[3]=>LIB 
[4]=>URD 
[5]=>ISL 
[6]=>PHY
[7]=>ISL 
[8]=>SCI 
[9]MATH 
[10]=>CHEM)

我尝试了以下

$ newarray = array();

foreach($ array as $ key => $ value){$ newarray [] = $ value; }

但是结果和我有第一个数组一样

$array=(
   Array([0] => ENG)
   Array([0] => ENG)
   Array([0] => URDU)
   Array([0] => LIB)
   Array([0] => URD)
   Array([0] => ISL)
   Array([0] => PHY)
   Array([0] => ISL)
   Array([0] => SCI)
   Array([0] => MATH)
   Array([0] => CHEM)
);

2 个答案:

答案 0 :(得分:0)

foreach ($array as $key => $value) 
{ 
    $newarray[] = $value[0];
}

答案 1 :(得分:0)

$array = [[0=>'ENG'],[0=>'IND'],[0=>'PAK'],[0=>'ING']];

$result = call_user_func_array('array_merge', $array);

echo "<pre>";
print_r($result);

上面提到的代码没有用。我做了一个数组并展平了。

输出:

Array
(
    [0] => ENG
    [1] => IND
    [2] => PAK
    [3] => ING
)