I want to create function display() to be called to display a sorted list of all previous names and marks entered. Name parameter should be set as optional. I am unable to call the function in the proper place. Note that the code is working without the function. I want to it to work by the function display(); Please help. Thanks
Here's my code:
<?php
session_start();
if(isset($_POST['lname']) && isset($_POST['marks'])){
if ($_POST['marks']<=100){
$_SESSION['info'][] = array($_POST['lname'] => $_POST['marks']);
}elseif (isset($_SESSION['info'])) {
$marks = array();
foreach($_SESSION['info'] as $key =>$values){
foreach($values as $name=>$mark){
$marks[$key] = $mark;
}
}
display();
function display(){
arsort($marks);
foreach($marks as $key => $value){
foreach($_SESSION['info'][$key] as $name => $marks){
printf("Name: %s Marks: %d   Grade: %s <br>", $name, $marks, CalcGrade($marks) );
}
}
}
}
}