chrisgrim
4 months ago
780
8
General

Issue with Modulo Operator I found on Stack Overflow

Posted 4 months ago by chrisgrim

I am using this stackover flow https://stackoverflow.com/questions/11764496/php-sequence-through-array-and-repeat-modulo-operator

/**
    * Assign the current user a color
    *
    * @return string
    */
    public function gethexColorAttribute()
    {
        $myarray = array('#54323','#504953','#405949'); 
        $count = count($myarray);
        foreach ($array as $index => $value) {
            return  $myarray[$index % $count];
        }   
    }

However it is throwing an error that $array isn't defined (makes sense) but I am not sure how it should be working. Thanks

Please sign in or create an account to participate in this conversation.