-1

I have a problem with my array, So my array is :

Array
(
   [0] => Array
    (
        [0] => Array
            (
                [sValue] => 1
            )

        [1] => Array
            (
                [sValue] => 2
            )

    )

) I want to get this array :

Array
(
  [0]=>1
  [1]=>2
)

I tried like this, but not work, it's get only the sValue = 1:

for($i=0;$i<count($aExpectedAnswers);$i++){
        foreach($aExpectedAnswers as $answer){
            $aFormatedAnswers[] = '\''.$answer[$i]['sValue'].'\'';
        }
    }

Help me please, Thx in advance

georg
  • 211,518
  • 52
  • 313
  • 390
Harea Costea
  • 275
  • 5
  • 19
  • what is exact structure of your main array? – ksg91 Jan 16 '15 at 11:58
  • 4
    possible duplicate of [Convert multidimensional array into single array](http://stackoverflow.com/questions/6785355/convert-multidimensional-array-into-single-array) – Mihai Jan 16 '15 at 11:58

3 Answers3

4
$aFormatedAnswers = [];
      foreach ($aExpectedAnswers as $answer) {
          if (is_array($answer)) {
             foreach ($answer as $item) {
              $aFormatedAnswers[] = $item;
              }
          } else {
           $aFormatedAnswers[] = $answer;
        } 
3
$result = array();
foreach($initial as $subArray){
    foreach($subArrray as $value){
        $result[] = $value;
    }
}
print_r($result);
Spoke44
  • 968
  • 10
  • 24
0

try this code:

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

hopefully helping.

Jogjakal
  • 75
  • 3