Search
 
SCRIPT & CODE EXAMPLE
 

PHP

convert object to array laravel

$person = new stdClass();
$person->firstName = "Taylor";
$person->age = 32;

//Convert Single-Dimention Object to array
$personArray = (array) $person;

//Convert Multi-Dimentional Object to Array
$personArray = objectToArray($person);
function objectToArray ($object) {
    if(!is_object($object) && !is_array($object)){
    	return $object;
    }
    return array_map('objectToArray', (array) $object);
}
Comment

laravel transform object to array

$users = AppUser::all();
$users = $users->toArray();
Comment

laravel object to array

function objectToArray(&$object)
{
    return @json_decode(json_encode($object), true);
}
Comment

PREVIOUS NEXT
Code Example
Php :: php to int 
Php :: laravel serve in another port 
Php :: array_key_exists vs isset 
Php :: how to load data from .env file in php 
Php :: wordpress get field 
Php :: php object foreach 
Php :: carbon two day ago 
Php :: is home page if wordpress 
Php :: how to search two needle in an array in_array php 
Php :: format time laravel 
Php :: eliminar ultimo caracter string php 
Php :: get name custom post type wordpress 
Php :: php all date formats 
Php :: laravel drop column 
Php :: Array and string offset access syntax with curly braces is deprecated in tcpdf.php 
Php :: linux set default php 
Php :: sort multidimensional array php by key 
Php :: codeigniter order by random 
Php :: php unset array key 
Php :: best pagination in laravel api with eloquent 
Php :: woocommerce order get_data() 
Php :: send mail test from laravel 
Php :: php artisan storage link cpanel 
Php :: php str to int 
Php :: array_key_exists vs in_array 
Php :: create laravel 9 auth 
Php :: if is alphabet php 
Php :: laravel limit foreach 
Php :: laravel timestamp 
Php :: php 7 strict mode 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =