Answers for "php array of arrays to array of objects"

PHP
9

php convert array to object

$object = (object) $array;
Posted by: Guest on March-17-2020
1

convert array to object php

$arrayResult = array_map(function($array){
    return (object)$array;
}, $yourOrinalArray);
Posted by: Guest on July-17-2020
0

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>';
}
?>
Posted by: Guest on October-31-2020

Code answers related to "php array of arrays to array of objects"

Browse Popular Code Answers by Language