La función Ds\Sequence::reversed() es una función incorporada en PHP que se utiliza para devolver la copia inversa del elemento de secuencia.
Sintaxis:
Ds\Sequence abstract public Ds\Sequence::reversed ( void )
Parámetros: Esta función no acepta ningún parámetro.
Valor devuelto: esta función devuelve la copia invertida de los elementos de secuencia.
Los siguientes programas ilustran la función Ds\Sequence::reversed() en PHP:
Programa 1:
<?php // Create new Sequence $seq = new \Ds\Vector([1, 2, 3, 4, 5]); // Display the sequence elements print_r($seq); echo("After reversing the sequence elements\n"); // Use reversed() function to reverse // the copy of sequence and display it print_r($seq->reversed()); ?>
Producción:
Ds\Vector Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) After reversing the sequence elements Ds\Vector Object ( [0] => 5 [1] => 4 [2] => 3 [3] => 2 [4] => 1 )
Programa 2:
<?php // Create new Vector $seq = new \Ds\Vector(["Geeks", "for", "Geeks", "Computer", "Science", "Portal"]); // Display the elements print_r($seq); echo("Sequence after reversing\n"); // Use reversed() function to reverse // the element and display it print_r($seq->reversed()); ?>
Producción:
Ds\Vector Object ( [0] => Geeks [1] => for [2] => Geeks [3] => Computer [4] => Science [5] => Portal ) Sequence after reversing Ds\Vector Object ( [0] => Portal [1] => Science [2] => Computer [3] => Geeks [4] => for [5] => Geeks )
Referencia: https://www.php.net/manual/en/ds-sequence.reversed.php