我的数组有问题,所以我的数组是:
Array
(
[0] => Array
(
[0] => Array
(
[sValue] => 1
)
[1] => Array
(
[sValue] => 2
)
)
) 我想得到这个数组:
Array
(
[0]=>1
[1]=>2
)
我试过这样,但不行,它只得到sValue = 1:
for($i=0;$i<count($aExpectedAnswers);$i++){
foreach($aExpectedAnswers as $answer){
$aFormatedAnswers[] = '\''.$answer[$i]['sValue'].'\'';
}
}
请提前帮助我
答案 0 :(得分:4)
$aFormatedAnswers = [];
foreach ($aExpectedAnswers as $answer) {
if (is_array($answer)) {
foreach ($answer as $item) {
$aFormatedAnswers[] = $item;
}
} else {
$aFormatedAnswers[] = $answer;
}
答案 1 :(得分:3)
$result = array();
foreach($initial as $subArray){
foreach($subArrray as $value){
$result[] = $value;
}
}
print_r($result);
答案 2 :(得分:0)
试试这段代码:
$aExpectedAnswers = array(
array(
0 => array('sValue'=>1),
1 => array('sValue'=>2),
)
);
$result = array();
foreach($aExpectedAnswers as $aea){
foreach($aea as $ae){
$result[] = $ae['sValue'];
}
}
print_r($result);
希望有所帮助。