Build content from several sub elements of an array in PHP

1

In PHP I receive an array organized in the following way:

[1] => Array
        (
            [id_liturgia] => 0000000001
            [antifonas] => Todos los días me sentaba en el templo...
                           |El Señor me ayuda, por eso no sentía ...
                           |El Señor Jesús se rebajó hasta someterse incluso ...
            [ordenes] => 1|2|3
            [salmos_ref] => Salmo 118, 105-112|Salmo 15|Cántico Flp 2, 6-11
            [temas] => Himno a la ley divina
                       |Cristo y sus miembros.. 
                       |Cristo, Siervo de Dios...
            [intros] => Éste es mi mandamiento... 
                        |Dios resucitó a Jesús...
                        |
            [partes] => 5|6|7
            [salmos] => Lámpara es tu palabra para mis pasos...
                        |Protégeme, Dios mío...
                        |Cristo, a pesar de su condición divina...
        )

I explain the situation as clearly as possible:

id_liturgia is a single field.

From the other elements of the array I need to build a content that combines them.

It is generally three psalms, but it could be more than three.

As you can see, each element of the psalm comes in a key of the array with an internal separator | .

The idea is to combine each element to build a text that has the respective parts of:

  • ordenes
  • antifonas
  • salmos_ref
  • temas
  • intros
  • partes
  • salmos

The final result would be:

  

0000000001

 one      

Every day I sat in the temple ...

     

Psalm 118, 105-112

     

Hymn to the divine law

     

This is my commandment ...

     

5

     

Lamp is your word for my steps ...

     

 two      

The Lord helps me, that's why I did not feel ...

     

Psalm 15

     

Christ and his members ..

     

God resurrected Jesus ...

     

6

     

Protect me, my God ...

     

 3      

The Lord Jesus lowered himself even to submit ...

     

Canticle Flp 2, 6-11

     

Christ, Servant of God ...

     

[nothing]

     

7

     

Christ, despite his divine condition ...

Currently I'm doing it with a explode on each part and then passing the different elements to a function that combines them. Something like this:

function getSalmoCompleto($sOrden, $sAntifona, $sRef, $sTema, $sIntro, $sParte, $sSalmo) 
{
  ....
}

I would like to know if there would be a simpler way to do it, without having to do explode on each element in antifonas , ordenes , etc and then pass each part of the explode to the function getSalmoCompleto () for me to build the content of the psalm.

    
asked by A. Cedano 17.06.2017 в 13:37
source

1 answer

-1

You can pass the array and access directly to each element of the array. $arr[0]['antifonas'] for example to access antifonas.

    
answered by 17.06.2017 в 13:57