Insert object into array

I have an array in php filled with Eventos Calendario objects, at some point in my script I need to enter a new object of the same type at the x position of this array. this is the code i use

$EventoLimite = new EventosCalendario(null,$Timestamp, $TipoEvento);                
var_dump($EventoLimite);
array_splice($this->EventosEntrada, $i, 0, $EventoLimite); //
var_dump($this->EventosEntrada[$i]);

And the "Var_Dumps" that I get:

object(EventosCalendario)[15]
  public 'FechaHora' => int 1376334000
  public 'FechaHoraOriginal' => null
  public 'Tipo' => string 'Entrada' (length=7)
  public 'Origen' => string 'Insertado' (length=9)
  public 'Subtipo' => null
  public 'ID' => null

int 1376334000

Why does the new slot in the array get only the value of the "FechaHora" property? I need to get the whole object in $ this-> EventosEntrada [$ i]. How can i do this?

+4
source share
2 answers

The "replace" argument must be the array itself, so you should write

array_splice($this->EventosEntrada, $i, 0, [$EventoLimite]); // note []s
+8
source

, - , , , , . , clsasses.

0

All Articles