I’m new to PHP. A friend was helping me learn this, but he’s not available for a while. I know some things may simply not make sense (i’m learning, and I know this isn’t exactly a beginners function).
GOAL:
1. Find highest and lowest value within the array ($lemons).
2. Switch the placement of said values. (IE: 6, 2, 7, 8, 0, 9 –> 6, 2, 7, 8, 9, 0).
Thanks!
<?php
function switcheroo($lemons) {
$min_lemons = min($lemons);
$max_lemons = max($lemons);
foreach ($lemons as $key => $value) {
if ($max_lemons > 0) {
$max_decoy = $min_lemons;
}
if ($min_lemons < 0) {
$min_decoy = $max_lemons;
}
}
return $lemons;
}
$lemons = array(6, 2, 7, 8, 0, 9);
print_r(switcheroo($lemons));
?>
This is probably not the most elegant solution, but it works as intended: