So I have an array of arrays (of which there is only one) so a multidimensional array. I want to insert more keys and values after each key => value that is currently there. Is there a way to do this?
$scores= array();
$scores[] = array('1' => '0', '2' => '83', '3' => '98', '4' => '57', '5' => '0', '6' => '76');
now after each key value, I want to add another that is something like
foreach($scores as $value){
if(80 > $value > 69){
$arrayToAdd = array(
'hasGrade' = 'true',
'grade' = 'C'
}
if(90 > $value > 79){
$arrayToAdd = array(
'hasGrade' = 'true',
'grade' = 'B'
}
if(100 > $value > 89){
$arrayToAdd = array(
'hasGrade' = 'true',
'grade' = 'A'
}
if($value == 100){
$arrayToAdd = array(
'hasGrade' = 'true',
'grade' = 'A*'
}
}
I haven't been using php for long and tried googling around but found nothing.
Any help is appreciated!
To solve this you can do something like this :
foreach($scores as $key => $value){
if($value > 69 && $value < 80){
$scores[$key]['someNameForYourGradesArray'] = array(
'hasGrade' = 'true',
'grade' = 'C'
}
}
if you don't want 2 levels of arrays, you can simply do :
$scores[$key]['hasGrade'] = 'true';
$scores[$key]['grade'] = 'C';
By the way the true if you want it in boolean, must not be in quotes