Jump to content

Spreegem

Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Everything posted by Spreegem

  1. I'm supposed to solve the problem using divide and conquer. Thanks for the speedy reply I'll have to go figure that out.
  2. So I'm working on a divide and conquer function to find the largest value in an array but I don't seem to get any value returned, when I echo theres nothing. Any ideas? Thanks a bunch in advance. <?php $array_size = 9; $numbers = array(8, 6, 18, 14, 24, 30, 12, 26, 16); //print_r($numbers); function largest($x, $y) { if ($x > $y) { echo">y<br>"; return $x; } else { echo"!>y<br>"; return $y; } } function maxArray($array_size, $first, $last) { if ($array_size == 1) { echo"=1<br>"; return largest($numbers[$first], $numbers[$last]); } else if($array_size > 1) { echo">1<br>"; return largest(maxArray((int)($array_size/2), $first, (int)($first + $last)/2), maxArray((int)($array_size/2), (int)($first + $last)/2, $last)); } } $max_value = maxArray($array_size, 0, ($array_size - 1)); echo "The largest value in the array is: $max_value"; ?>
  3. Thanks a bunch, but it was actually working from the beginning, its just where I was trying to use it the if was incorrect and so I didnt think it was working even though it was. Thank you for your help!
  4. I am trying to sesssion an array, and then get some data from the array after some form data is submitted to another page, but when I try and get data from it, the array is blank. Is it even possible to session arrays, or am I doing something wrong in my code? [code] //From page 1 $_SESSION['h_class'] = $class_array; //From Page 2 $class_array = $_SESSION['h_class']; $h_class = $class_array["$num"]; [/code]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.