How to use a function inside another function in php?

-1

I need to use function inside another function ...

function formata_data( $datacad ){
    $datacad = explode(' ', $data);
    $datacad = $data[0];
    $datacad = explode("-", $data);
    $datacad = $data[2]."-".$data[1]."-".$data[0];
    return $datacad;
}

Now I have a function list users that need to return the data including data de cadastro and format it with the created function.

function usuarios(){
    // listando usuarios
    $datacadastro = ("Y-m-d H:i:s");
    $datacadastro = ; //usar a função formata_data para formatar o retorno da data no banco
}
    
asked by anonymous 09.11.2015 / 22:29

1 answer

5

To use the function you create, just use the same way as any one pre-existing in PHP:

function usuarios(){
    // listando usuarios
    $datacadastro = formata_data("Y-m-d H:i:s");
}

However, your function needs to return something, otherwise it will not help you much. Failed to put in return what the function should return . See:

function formata_data( $datacad ){
    $datacad = explode(' ', $data);
    $datacad = $data[0];
    $datacad = explode("-", $data);
    $datacad = $data[2]."-".$data[1]."-".$data[0];
    return $datacad; // Aqui acrescentamos o que deve ser retornado.
}
    
09.11.2015 / 22:38