Increment value in the name of a function

0

Good afternoon, guys! Next, I have three file fields in a table from my bank, they are: File1, File2, and File3. I also have a get and a set for each of them. The question is, I wanted to run a for () and in every loop increment the get.

    <?php if(isset($pedido) && $pedido->getFile1() != null): ?>
     <?php for($i=0;$i<$count;$i++): ?>
        <div class="list-group">
            <div class="list-group-item">
                <a target="_blank" href="<?php echo '/files/'.$pedido->getFile[$i](); ?>">
                    <i class="fa fa-file-o"></i>
                    <strong>
                    Arquivo <?php echo $i; ?>
                    <i class="fa fa-lock"></i>
                    </strong>
                </a>
                <br />
                <p>
                    <?php echo $pedido->getFile[i](); ?>
                </p>
            </div>
        </div>
     <?php endfor; ?> 
 <?php else: ?>

that is, with each increment would get getFile1 (), getFile2, getFile3. Would you have some way to do that? I know that syntax [$ i] there does not work, it was more to exemplify.

    
asked by anonymous 29.05.2018 / 18:32

1 answer

0

I know the following ways to do this:

<?php for($i=0;$i<$count;$i++): ?>
    $nomeMetodo = 'getFile' . $i;

    // 1
    $this->{$nomeMetodo}($arg1, $arg2, $arg3);
    // 2
    $this->$nomeMetodo($arg1, $arg2, $arg3);
    // 3
    call_user_func_array(array('namespaceComNomeDaClasse', $nomeMetodo), array($arg1, $arg2, $arg3));

<?php endfor; ?> 
    
30.05.2018 / 14:41