Forgive the word game.
I have to cycle an array and sum the values, then multiply for the price (i already know how to do that).
The object is composed of 64 fields called val1, val2, val3 etc .. each field has a simple_array with the value of the quantity.
I get these data from the database using doctrine.
$item = $this->getDoctrine()->getRepository(ExpertationsAdvanced::class)->findBy(['father' => $id]);
dump($item[0]->getVal1());
for($i = 1; $i < 64; $i++) {
dump(${'$item[0]->getVal' . $i . '()'});
$i++;
if(${'$item[0]->getVal' . $i . '()'} == null) {
$return = '0';
} else {
$return = array_sum(${'$item[0]->getVal' . $i . '()'} );
}
dump($return);
}
the first dump return the array i'm requesting for, with no problems, but in the forloop, i get erro Notice: Undefined variable: $item[0]->getVal1().
I think I'm using the wrong logic but maybe worked so mutch time and can't see a way.