Functions frustrating

Good morning everyone. This is my first post on this website. I am looking for some help. I have spent the last four hours trying to figure out functions with arrays.

I want to use the ‘ucwords’ to capitalize the first letter of each name in my array. I have tried to define a function to do so but I have been unsuccessful multiple times. I have tried so many different variations and to no avail. If someone could help me fix my problem I would really appreciate it.

My ultimate goal is to print out each persons name capitalized with their score and then use their score in a loop to determine what year they are in.

<?php //array keys&values $students = array( 'rick' => 124, 'morty' => 24, 'summer' => 48, 'beth' => 75, 'jerry' => 32, 'bird_man' => 97); ?> <?php $get_proper_name = ucwords($studentname); ?> <?php foreach ($students as $studentname=>$score){ echo "$studentname has $score credits. They are considered a .$get_student_year.
"; } ?> <?php if ($score <= '30'){ echo " a freshman, I need " . $freshman1 . " more credits to be considered a sophomore";} if ($score <= '60'){ echo " a sophomore, I need " . $sophomore1 . " more credits to be considered a junior";} if ($score <='92'){ echo " a junior, I need " . $junior1 . " more credits to be considered a senior";} if ($score >'92'){ echo " a senior";} ?> <?php //student year function get_student_year ($credits_needed, $score) { $student_year = "$credits_needed - $score"; return $student_year; } ?> <?php //grad credits function get_grad_credits ($credits_needed, $score) { $grad_credits = "$credits_needed - $score"; return $grad_credits; } ?>
<?php //next level
function get_next_level  ($credits_needed, $score) {
	$next_level = "$credits_needed - $score";

	return $next_level;
}
 ?>

The whole thing is a mess. Start with the most basic part and go from there. Stop with the constant opening and closing of Php. Font is deprecated. Use CSS

[php]<?php
$students = array(
‘rick’ => 124,
‘morty’ => 24,
‘summer’ => 48,
‘beth’ => 75,
‘jerry’ => 32,
‘bird_man’ => 97
);

foreach ($students as $studentname => $score)
{
echo “Student " . ucwords($studentname) . " Score: $score
”;
}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service