How to break lines in the output of an Array?

0

Good afternoon, I have an array in PHP that shows the date the last backup of each store was made, and the information is shown as follows:

  LOJA01 - Bkp 01 teve o ultimo backup em1: 02-01-2017.
  LOJA01 - Bkp 02 teve o ultimo backup em3: 30-12-2016.
  LOJA01 - Bkp 03 teve o ultimo backup em3: 31-12-2016.
  LOJA03 - Bkp 01 teve o ultimo backup em1: 10-12-2016.
  LOJA03 - Bkp 02 teve o ultimo backup em1: 11-12-2016.
  LOJA03 - Bkp 03 teve o ultimo backup em1: 09-12-2016.
  LOJA05 - Bkp 01 teve o ultimo backup em1: 10-12-2016.
  LOJA05 - Bkp 02 teve o ultimo backup em1: 11-12-2016.
  LOJA05 - Bkp 03 teve o ultimo backup em1: 09-12-2016.
  LOJA06 - Bkp 01 teve o ultimo backup em1: 11-12-2016.
  LOJA06 - Bkp 02 teve o ultimo backup em1: 11-12-2016.
  LOJA06 - Bkp 03 teve o ultimo backup em1: 09-12-2016.

I would like to know if there is any way with each different store that it skips a line or separate, notice that each store has bkp 01, 02 and 03 ...

The output I'd like would look something like this:

  LOJA01 - Bkp 01 teve o ultimo backup em1: 02-01-2017.
  LOJA01 - Bkp 02 teve o ultimo backup em3: 30-12-2016.
  LOJA01 - Bkp 03 teve o ultimo backup em3: 31-12-2016.

  LOJA03 - Bkp 01 teve o ultimo backup em1: 10-12-2016.
  LOJA03 - Bkp 02 teve o ultimo backup em1: 11-12-2016.
  LOJA03 - Bkp 03 teve o ultimo backup em1: 09-12-2016.

  LOJA05 - Bkp 01 teve o ultimo backup em1: 10-12-2016.
  LOJA05 - Bkp 02 teve o ultimo backup em1: 11-12-2016.
  LOJA05 - Bkp 03 teve o ultimo backup em1: 09-12-2016.

  LOJA06 - Bkp 01 teve o ultimo backup em1: 11-12-2016.
  LOJA06 - Bkp 02 teve o ultimo backup em1: 11-12-2016.
  LOJA06 - Bkp 03 teve o ultimo backup em1: 09-12-2016.

My Array looks like this:

<?php
error_reporting(0);
ini_set(“display_errors”, 0 );
$lista_lojas = array(   
    "LOJA01 - Bkp 01"  => "servers/01/bk001/Mpcfg.ini",
    "LOJA01 - Bkp 02"  => "servers/01/bk002/Mpcfg.ini",
    "LOJA01 - Bkp 03"  => "servers/01/bk003/Mpcfg.ini",
    "LOJA03 - Bkp 01"  => "servers/03/bk001/Mpcfg.ini",
    "LOJA03 - Bkp 02"  => "servers/03/bk002/Mpcfg.ini",
    "LOJA03 - Bkp 03"  => "servers/03/bk003/Mpcfg.ini",
    "LOJA05 - Bkp 01"  => "servers/05/bk001/Mpcfg.ini",
    "LOJA05 - Bkp 02"  => "servers/05/bk002/Mpcfg.ini",
    "LOJA05 - Bkp 03"  => "servers/05/bk003/Mpcfg.ini",
    "LOJA06 - Bkp 01"  => "servers/06/bk001/Mpcfg.ini",
    "LOJA06 - Bkp 02"  => "servers/06/bk002/Mpcfg.ini",
    "LOJA06 - Bkp 03"  => "servers/06/bk003/Mpcfg.ini",
);
?>

Page that displays array data:

    <?php

        date_default_timezone_set('America/Sao_Paulo');

        // Inclui o arquivo com os caminhos dos PLUEAN.BIN 
        include_once('includes/array_servers.php');

        foreach($lista_lojas as $l_nome => $l_caminho) 
        { ?>

        <?php 

            $today = date('d-m-Y'); //recebe a data atual
            $seconds = strtotime($today); //converte para segundos
            $diff_date = date("d-m-Y",($seconds - 345600));
            $data_antiga = "31-12-1969";
            // echo $diff_date;
            $data_mod = date ("d-m-Y", filemtime($l_caminho));
            //echo $data_obsoleta;


                    if (($data_mod <= $diff_date) and ($lojaAt == $lojaAt))

                    { ?>
                        <img src="img/down.png" width="15" height="15"/>&nbsp;
                            <?php echo "$l_nome teve o ultimo backup em1: " . date ("d-m-Y.", filemtime($l_caminho));
                             echo $lojaAt; echo "<br>"  ;
                    } elseif (($data_mod == $data_antiga) and ($lojaAt == $lojaAt))
                    {?>
                        <img src="img/down.png" width="15" height="15"/>&nbsp;
                            <?php echo "$l_nome teve o ultimo backup em2: " . date ("d-m-Y.", filemtime($l_caminho));
                            echo $lojaAt; echo "<br>"   ;

                    } elseif (($data_mod >= $diff_date) and ($lojaAt == $lojaAt)) 
                    {?>
                        <img src="img/up.png" width="15" height="15"/>&nbsp;
                            <?php echo "$l_nome teve o ultimo backup em3: " . date ("d-m-Y.", filemtime($l_caminho));
                            echo $lojaAt; echo "<br>"   ;

                    } else

                    ?> 
<?php   } ?>
    
asked by anonymous 02.01.2017 / 20:49

1 answer

2

One solution would be to treat at the time of printing the value. + - Thus:

<?php


$lista_lojas = array(   
    "LOJA01 - Bkp 01"  => "servers/01/bk001/Mpcfg.ini",
    "LOJA01 - Bkp 02"  => "servers/01/bk002/Mpcfg.ini",
    "LOJA01 - Bkp 03"  => "servers/01/bk003/Mpcfg.ini",
    "LOJA03 - Bkp 01"  => "servers/03/bk001/Mpcfg.ini",
    "LOJA03 - Bkp 02"  => "servers/03/bk002/Mpcfg.ini",
    "LOJA03 - Bkp 03"  => "servers/03/bk003/Mpcfg.ini",
    "LOJA05 - Bkp 01"  => "servers/05/bk001/Mpcfg.ini",
    "LOJA05 - Bkp 02"  => "servers/05/bk002/Mpcfg.ini",
    "LOJA05 - Bkp 03"  => "servers/05/bk003/Mpcfg.ini",
    "LOJA06 - Bkp 01"  => "servers/06/bk001/Mpcfg.ini",
    "LOJA06 - Bkp 02"  => "servers/06/bk002/Mpcfg.ini",
    "LOJA06 - Bkp 03"  => "servers/06/bk003/Mpcfg.ini",
);

$lojaAnt = '';
foreach($lista_lojas as $key => $item) {

    $lojaAt = explode(' ',$key)[0];                         ;

    if ($lojaAt<>$lojaAnt){
        echo "<br>";
    }

    echo $key."  ".$item."<br>";    
    $lojaAnt=$lojaAt;
}

/*Saída:

LOJA01 - Bkp 01 servers/01/bk001/Mpcfg.ini
LOJA01 - Bkp 02 servers/01/bk002/Mpcfg.ini
LOJA01 - Bkp 03 servers/01/bk003/Mpcfg.ini

LOJA03 - Bkp 01 servers/03/bk001/Mpcfg.ini
LOJA03 - Bkp 02 servers/03/bk002/Mpcfg.ini
LOJA03 - Bkp 03 servers/03/bk003/Mpcfg.ini

LOJA05 - Bkp 01 servers/05/bk001/Mpcfg.ini
LOJA05 - Bkp 02 servers/05/bk002/Mpcfg.ini
LOJA05 - Bkp 03 servers/05/bk003/Mpcfg.ini

LOJA06 - Bkp 01 servers/06/bk001/Mpcfg.ini
LOJA06 - Bkp 02 servers/06/bk002/Mpcfg.ini
LOJA06 - Bkp 03 servers/06/bk003/Mpcfg.ini */

Update:

Inserted the solution in the code you provided:

 <?php

date_default_timezone_set('America/Sao_Paulo');

// Inclui o arquivo com os caminhos dos PLUEAN.BIN 
include_once('includes/array_servers.php');
$lojaAnt = '';
foreach ($lista_lojas as $l_nome => $l_caminho) {
?>

        <?php

    $today       = date('d-m-Y'); //recebe a data atual
    $seconds     = strtotime($today); //converte para segundos
    $diff_date   = date("d-m-Y", ($seconds - 345600));
    $data_antiga = "31-12-1969";
    // echo $diff_date;
    $data_mod    = date("d-m-Y", filemtime($l_caminho));
    //echo $data_obsoleta;

    //$lojaAt = explode(' ',$l_nome)[0];  


    if ($lojaAt <> $lojaAnt) {
        echo "<br>"; //Colocar aqui o código para quebrar a linha
    }

    $lojaAnt = $lojaAt;


    if (($data_mod <= $diff_date) and ($lojaAt == $lojaAt)) {
?>
                      <img src="img/down.png" width="15" height="15"/>&nbsp;
                            <?php
        echo "$l_nome teve o ultimo backup em1: " . date("d-m-Y.", filemtime($l_caminho));
        echo $lojaAt;
        echo "<br>";
    } elseif (($data_mod == $data_antiga) and ($lojaAt == $lojaAt)) {
?>
                      <img src="img/down.png" width="15" height="15"/>&nbsp;
                            <?php
        echo "$l_nome teve o ultimo backup em2: " . date("d-m-Y.", filemtime($l_caminho));
        echo $lojaAt;
        echo "<br>";

    } elseif (($data_mod >= $diff_date) and ($lojaAt == $lojaAt)) {
?>
                      <img src="img/up.png" width="15" height="15"/>&nbsp;
                            <?php
        echo "$l_nome teve o ultimo backup em3: " . date("d-m-Y.", filemtime($l_caminho));
        echo $lojaAt;
        echo "<br>";

    } else
?> 
<?php
}
?> 
    
02.01.2017 / 21:54