Ad
  • Custom User Avatar

    So, been struggling with this for an hour now, and i can't quite understand what i'm doing wrong. i even quit the kata to see the answers, but i still want to know what was wrong with my solution. any reply will be highly appreciated.
    my code below (nowhere near good practice probably but i'm new to php so i'm trying to understand the concept before using methods like array_map()

    function comp($a1, $a2) {
    $answer = true;
    $arr = array();
    foreach($a1 as $val) {
    $sqr = $val*$val;
    array_push($arr, $sqr);
    }
    sort($arr);
    sort($a2);
    if (is_null($a1) || is_null($a2) || $arr != $a2 || count($arr) != count($a2) || !is_array($a1) || !is_array($a2) || count($a1) == 0 || count($a2) == 0){
    return false;
    } else {
    return true;
    }
    }