在同一个文件助手codeigniter中调用另一个函数

halo everyone. now im doing task using CI (CodeIgniter) framework. i made a function in helper file. the question is. do we can call another function in same helper file. i give example

file "common_helper.php"

function calculation($param)
{
    $result = $this->discount($param);
    return $result;
}

function discount($param)
{
    $total = $param * 10%;
    return $total;
}

so in function "calculation" want to call function "discount".. but i cant use "$this->discount($param)". is there another way for this?

the second is

i got error when i create this function in helper

function flatten_multi_array_and_get_unique($multi)
{
    $objTmp = (object) array('aFlat' => array());
    array_walk_recursive($multi, create_function('&$v, $k, &$t', '$t->aFlat[] = $v;'), $objTmp);

    $res = array_unique($objTmp->aFlat);

    return $res;
}

the error warning is "Function create_function() is deprecated" what should i do?

For the second part you can use an anonymous function aka. closure function

function flatten_multi_array_and_get_unique($multi)
{
    $objTmp = (object) array('aFlat' => array());
    array_walk_recursive($multi, function(&$v, $k, &$t){ $t->aFlat[] = $v; }, $objTmp);

    $res = array_unique($objTmp->aFlat);

    return $res;
}

Find interesting? Read more