How to include asset fields in query in php? I am trying to figure out how to return asset field(s) in a PHP entry query. Also if I could learn how to return "custom fields" when returning an Object that would be great too! Right now I am having to specify asArray() to even get access to most of my "custom fields" 

As as example: I have a Vehicle Entry which has a custom field with the handle of price (number field) and another custom field (asset field) with the handle of images. When I execute the query without specifying the asArray() param I cannot find the custom fields included in the results. But if I specify asArray() then they are all there with the exception of my images field which I think is because it is an asset field or possible because it can be a collection of images? How can I make sure all the fields tied to an entry are returned in my query?

Here are some examples of queries and the corresponding results:

PHP Query without asArray():

$entry_query = Entry::find()
-&gt;section('inventory')
-&gt;all();


Returns: 


PHP Query results with asArray():

$entry_query = Entry::find()
-&gt;section('inventory')
-&gt;asArray();




However even when specifing to make the result set an array I still cannot figure out how to include the 'images' field. 

The images is a field added to the section (see below)


I am having a difficult time finding an answer via the documentation or an example of someone doing the same. All the examples i find are for the template side in twig. 

Thanks!
You can skip the asArray() part, as the object has all you need:

// This bit returns only the query that defines what objects to get
$entryQuery = Entry::find()-&gt;section('inventory');

/*
 * This will get you one object, based on the query. 
 * Use all() if you want an array of objects
 */
$entry = $entryQuery-&gt;one();

// Of course, this could be written as
$entry = Entry::find()-&gt;section('inventory')-&gt;one();

/* 
 * Thanks to Yii2's magic getters and setters, 
 * and the way Craft uses them, any custom field can be 
 * obtained by using the field's handle:
 */
$customFieldContent = $entry-&gt;customFieldHandle;

/*
 * If the custom field is any kind of relation field (assets, categories, tags ...),
 * this custom field attribute would return a new query object.
 * You'd need to call all() or one() again to get the actual related objects:
 */
 $images = $entry-&gt;customImagesFieldHandle-&gt;all();

/*
 * To improve performance, you can eager load the images:
 */
$entry = Entry::find()
    -&gt;section('inventory')
    -&gt;with(['customImagesFieldHandle'])
    -&gt;one();

/*
 * ... which would result in an array of images as the value of the
 * customImagesFieldHandle attribute
 */
$images = $entry-&gt;customImagesFieldHandle;


Some light reading:

About entry queries

About eager loading

Addition, after seeing exactly what it is you want. Use Craft's (or actually Yii's) ArrayHelper map() function to loop through your entries and mapping entry content to what you want:

use craft\helpers\ArrayHelper

// Use the map() function to do what you want
$entries = Entry::find()-&gt;section('inventory')-&gt;all();

$entriesAsYouWantThem = ArrayHelper::map($entries, 'id', function($entry) {
    return (object)[
        'images' =&gt; $entry-&gt;images-&gt;all(), // or without all, if you use -&gt;with()
        'price' =&gt; $entry-&gt;price,
        'year' =&gt; $entry-&gt;year,
        ... All other fields
    ];
});