How to remove the first value inside an array?

0

I have the following array:

array(3) {
  [0]=>
  string(22) "VALOR 1"
  [1]=>
  string(10) "VALOR 2"
  [2]=>
  string(14) "VALOR 3"
}

I need to show all values of this array but delete the first, which in this case is "VALUE 1". How to remove the first value from the array? Since the string can be anything.

I tried to use array_shift () but it ends up disappearing with my array and leaving only the first string.

    
asked by anonymous 22.03.2017 / 16:08

1 answer

3

You should use array_shift() , but be careful not to overwrite the array, because it returns the removed element, not the resulting array.

That is:

$arraycompleto = [1,2,3];

// Edit: se você precisa manter um valor qualquer na primeira posição 
// e a chave é sempre 0, isso vai resolver:
$arraycompleto[0] = '';
var_dump( $arraycompleto ); // ['',2,3]

// Se a primeira chave não é zero ou você precisa do valor original:
$elementoretirado = array_shift( $arraycompleto );
array_unshift( $arraycompleto, '' );

var_dump( $arraycompleto ); // ['',2,3]
var_dump( $elementoretirado ); // 1;
    
22.03.2017 / 16:12