SmartArray wraps your database rows so template code gets shorter and safer at once: filter, sort, and group with chainable methods, and echo fields directly. Fields HTML-encode themselves the moment you output them.
New to SmartArray? The Basics reads in order, and the first two pages alone cover everything a typical list-plus-detail template needs. The other sections are standalone: open whichever matches your task.
- Getting Started - Install, your first collection, loops, single rows, and formatting fields with SmartString methods.
- Displaying Fields - Reading fields, fallbacks for blank values with
or(), "no results" messages, and the guards that stop the page for required records. - Outputting HTML - How auto-encoding works, trusted HTML with
rawHtml(), loop layout withisFirst()/isLast()/position(), and the raw-keys gotcha. - Filtering and Sorting - Narrowing loaded results with
where(),whereNot(),whereInList(), andfilter(), plussortBy(),sort(), andunique(). - Transforming and Grouping - Reshaping results with
column(),indexBy(),groupBy(),map(), andimplode(). - Using SmartArray Without SmartStrings - Plain-value collections for JSON, CSV, email, and CLI output, converting between modes, and type hints.
- Common Patterns - Copy-paste recipes for real template tasks: related names without a join, select dropdowns, grouped headings, id lists for SQL.
- Method Reference - Every method in one place, grouped by what it returns.
- Troubleshooting - Common error messages and behavior gotchas, with fixes.
- Performance - What SmartArray costs vs plain arrays: about 0.002 ms per 25-row page and 300 bytes per row.
- AI Reference - The complete API in one dense file, written for AI coding assistants.