Menu

1 / 3

Your PHP API Sends Keys 10 Then 2. Your TypeScript Client Reads 2 Then 10

DEV Community: php·Gabriel Anhaia·9 days ago
#b5lOu41q
#devto#dev#order#keys#object
Reading 0:00
15s threshold

Book: PHP to TypeScript

Also by me: The TypeScript Library — the 5-book collection

My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools

Me: xgabriel.com | GitHub

Your PHP controller builds the shipping options for a checkout dropdown. Product wants Express on top, so you build the array in that order: ['10' => 'Express', '2' => 'Standard', 'pickup' => 'Store pickup'] . The JSON leaves the server with the keys in that order. The TypeScript frontend loops over it with Object.entries , and Standard renders first.

Nobody sorted anything. Both runtimes did exactly what their specs say. A PHP array remembers insertion order for every key.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.