So I need a function to be able to add elements to a associative array, along with a counter to count the number of this function called. Here is what I got so far:
<?php
//1
$Globals = [];
$counter = 0;
function array_push_assoc($course, $courseCode, $courseName){
$course[courseCode] = $courseName;
return $course();
$counter ++;
}
$Globals = array_push_assoc($Globals, 'CIS370', 'Introduction to Web Development');
$Globals = array_push_assoc($Globals, 'CIS475', 'Advance Web Development');
$Globals = array_push_assoc($Globals, 'CIS560', 'Introduction to Syber Security');
$Globals = array_push_assoc($Globals, 'CIS564', 'Hacking Technic');
//2
echo 'You have a total of $counter courses now!';
?>
Obviously it is wrong, can someone let me know where and how to do this properly? Thanks
Globals[$courseCode] = $courseNameinstead of calling your functions. Then just doecho 'You have a total of ' . count($Globals) . ' courses now!';return $course(), I imagine, you should drop off the()since I don't think that's a function.