Mount an array with result of a foreach with php

0

Hello

I'm not able to mount an array with results from a foreach.

I have and foreach

foreach($Result as $Aluno):
    extract($Aluno);

    echo '<tr>';
    echo "<td class='nome'>{$Nome}</td>";
    echo "<td class='centro'>{$finalNota}</td>";
    echo '</tr>';
endforeach;       

Displaying:

Aluno | Pontuação
Pedro | 1.5
Ana   | 3
Maria | 5.2
José  | 4

I need to mount an array with the punctuation having like this:

Array
(
    0 => 1.5
    1 => 3
    2 => 5.2
    3 => 4
)

Thank you

    
asked by anonymous 28.11.2018 / 21:25

1 answer

1

Do so in your cod

foreach($Result as $Aluno):
    extract($Aluno);

    echo '<tr>';
    echo "<td class='nome'>{$Nome}</td>";
    echo "<td class='centro'>{$finalNota}</td>";
    echo '</tr>';
endforeach; 

Turn it into this:

$notas=array();
foreach($Result as $Aluno):
    extract($Aluno);

    echo '<tr>';
    echo "<td class='nome'>{$Nome}</td>";
    echo "<td class='centro'>{$finalNota}</td>";
    echo '</tr>';
    $notas[]=$finalNota;
endforeach;       

At the end of foreach you already have the array notes the way you want it.

    
28.11.2018 / 21:39