The code:
public function couts_complets($chantier,$ponderation=100){
    function ponderation($n)
    {
        return($n*$ponderation/100); //this is line 86
    }
            ...
    }
What I'm trying to do: to declare a function B inside a function A in order to use it as a parameter in
                            array_map().
My problem: I get an error:
Undefined variable: ponderation [APP\Model\Application.php, line 86]
Try this:
public function couts_complets($chantier,$ponderation=100){
    $ponderationfunc = function($n) use ($ponderation)
    {
        return($n*$ponderation/100);
    }
        ...
    $ponderationfunc(123);
}
                        As of php 5.3 you can use anonymous functions. Your code would look like this (untested code warning):
public function couts_complets($chantier,$ponderation=100) {
    array_map($chantier, function ($n) use ($ponderation) {
        return($n*$ponderation/100); //this is line 86
    }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With