mercredi 30 septembre 2015

How can I properly call any math related function in a class/controller?

I tried to use the factorial php build in function gmp_fact() in one of my function in my class/controller.

I keep getting:

Call to undefined function App\Http\Controllers\gmp_fact()

Does anybody know why ? or How do I fix it ?

How's come I can use other functions like strlen, str_split, and so on ... ?

Do I need to include any kind of Math library or something ?


My Controller

<?php

namespace App\Http\Controllers;
use View, Input, Redirect;

class CodeController extends Controller {

    public function getFactorial($num)
    {
        $fact = 1;
        for($i = 1; $i <= $num ;$i++)
            $fact = $fact * $i;
        return $fact;
    }

    public function codingPuzzle()
    {
        return View::make('codes.puzzle');
    }

    public function codingPuzzleProcess()
    {

        $word     = strtoupper(Input::get('word'));
        $length   = strlen($word);
        $max_value = ($length * 26);
        $characters = str_split($word);

        $num = 1 ;
        $index = 1;

        sort($characters);

        //dd($characters);

        foreach ( $characters as $character) {
            $num += gmp_fact($index) * $index;
            $index ++;


        }

        return Redirect::to('/coding-puzzle')
            ->with('word', $word )
            ->with('num', $num )
            ->with('success','Submit successfully!');

    }


}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1haPuSS
via IFTTT

Aucun commentaire:

Enregistrer un commentaire