I created a function that should in theory create an array from another array (basically what i want to do its bring it down 1 level).
My problem is that somehow the code creates another array inside the new array when it shouldn't.... and even more the output is rather strange. The final array should all be in the same level but somehow it creates it multidimensional and with extra values.
The problem seems to be in the loop, but i can't see where
any help is appreciated.
public function pullCompetencyByCID ( $cID ) {
$sql = 'SELECT * FROM ldc_competency_'.$this->lang.' WHERE cID='.$cID;
$result = $this->db->query($sql)->fetchAll(PDO::FETCH_ASSOC);
foreach ( $result as $key2 => $val2 ){
switch ($key2){
case 'cName': $cName = $val2;
break;
case 'cID': $cID = $val2;
break;
case 'cLevel': $cLevel = $val2;
break;
case 'cDetails': $cDetails = $val2;
break;
case 'cSummary': $cSummary = $val2;
break;
}
}
$pullCompetency = array('cName'=>$cName,'cID'=>$cID, 'cLevel'=>$cLevel, 'cDetails'=>$cDetails, 'cSummary'=>$cSummary);
return $pullCompetency;
}
The output of that code is
Array (
[cName] => Array (
[cID] => 2
[cName] => dos
[cLevel] => 2
[cDetails] => doss
[cSummary] => dosssss
)
[cID] => 2
[cLevel] =>
[cDetails] =>
[cSummary] =>
)
The output of just the $result is
Array (
[0] => Array (
cID] => 2
[cName] => dos
[cLevel] => 2
[cDetails] => doss
[cSummary] => dosssss
)
)
to avoid confusion the desired result should be
Array (
[cID] => 2
[cName] => dos
[cLevel] => 2
[cDetails] => doss
[cSummary] => dosssss
)
return $result? What is that loop supposed to do?!SELECT cName, cID, cLevel, cDetails, cSummary ...