php create object
$x = (object) [
'a' => 'test',
'b' => 'test2',
'c' => 'test3'
];
var_dump($x);
/*
object(stdClass)#1 (3) {
["a"]=>
string(4) "test"
["b"]=>
string(5) "test2"
["c"]=>
string(5) "test3"
}
*/
php create object
$x = (object) [
'a' => 'test',
'b' => 'test2',
'c' => 'test3'
];
var_dump($x);
/*
object(stdClass)#1 (3) {
["a"]=>
string(4) "test"
["b"]=>
string(5) "test2"
["c"]=>
string(5) "test3"
}
*/
make a object php
$object = new stdClass();
$object->property = 'Here we go';
var_dump($object);
/*
outputs:
object(stdClass)#2 (1) {
["property"]=>
string(10) "Here we go"
}
*/
php dar echo em um stdClass
<?php
$obj = (object) array('1' => 'foo');
var_dump(isset($obj->{'1'})); // outputs 'bool(true)' as of PHP 7.2.0; 'bool(false)' previously
var_dump(key($obj)); // outputs 'string(1) "1"' as of PHP 7.2.0; 'int(1)' previously
?>
php create array of objects
<?php
class Person
{
public $name;
public $age;
function birthday($age){
$age = $age + 1;
return $age;
}
}
$person1 = new Person();
$person1->name = 'David';
$person1->age = '23';
$person2 = new Person();
$person2->name = 'Nuno';
$person2->age = '21';
$person2->age = $person2->birthday($person2->age);
$persons = array($person1, $person2);
foreach ($persons as $person) {
echo 'My name is ' . $person->name . ' and i have ' . $person->age . " years old";
echo '<br>';
}
?>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us