Skip to content

Instantly share code, notes, and snippets.

@coderdiaz
Created March 12, 2015 18:15
Show Gist options
  • Save coderdiaz/6c284e504a628178c377 to your computer and use it in GitHub Desktop.
Save coderdiaz/6c284e504a628178c377 to your computer and use it in GitHub Desktop.
Agregar datos a un objeto en PHP
<?php
$data1 = new stdClass;
$data1->id = 10;
$data1->url = 11;
$data1->otrodato = 12;
$data2 = new stdClass;
$data2->id = 13;
$data2->url = 14;
$data2->otrodato = 15;
$data1->newdato = 14;
$array = array(
$data1,
$data2
);
var_dump($array);
@coderdiaz
Copy link
Author

<?php

$data1 = new stdClass;
$data1->id = 10;
$data1->url = 11;
$data1->otrodato = 12;

$data2 = new stdClass;
$data2->id = 13;
$data2->url = 14;
$data2->otrodato = 15;

$data1->newdato = 14;

$array_principal = new stdClass;
$array_principal->deposito_x = $data1;
$array_principal->deposito_y = $data2;

var_dump($array_principal);

Output here: http://ideone.com/m5liVR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment