Urgent.News

What's breaking now, across thousands of outlets.

Tech

A real world case of recursion done right in PHP

Nick Cosentino @DevLeaderCa posted this message about recursion on X, ex Twitter, in October 2025, which received over 460 replies. // Detect dark theme var iframe = document.getElementById('tweet-1984123215170421060-448'); if (document.body.className.includes('dark-theme')) { iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1984123215170421060&theme=dark" } I quote an excerpt: I've…

Nick Cosentino shared a real-world example of recursion on Twitter in October 2025, receiving significant engagement. He argues that recursion can be simpler than its iterative counterpart in certain cases. To illustrate this, he uses the Fibonacci sequence as an example.

The recursive algorithm for the Fibonacci sequence is defined as follows:

- If n = 0 or n = 1, fib(n) = 1

- Otherwise, fib(n) = fib(n - 1) + fib(n - 2)

This recursive definition can be implemented without loops or intermediate variables, showcasing the power of recursion in such scenarios.

The PHP UI Builder library, used for building application UIs, is particularly well-suited for recursive algorithms due to its hierarchical component structure. Components can have properties, contain other components, and be either real or virtual. The library introduces virtual components such as When, Each, Pick, and List to handle various data processing scenarios.

For example, the When component takes a condition and generates a component if the condition is met. The Each component generates a component for each element in an array of data. The Pick component generates a different component based on the first true condition from a list of conditions. The List component aggregates a set of components into one.

By using a recursive approach, the UI Builder can efficiently handle complex hierarchical structures, making it well-suited for building dynamic and interactive user interfaces.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

The secret was correct. The first byte wasn't.

Our deploy tool pushed a fresh API token to production. It reported success. The token was correct. Every request then failed with this: Cannot convert argument to a ByteString because the character…

FastAPI's new app.frontend() fixes a route-order bug in manual SPA serving

Put a FastAPI catch-all route above your API route by mistake and a request to /api/ping returns HTTP 200. The body is your single-page app's index.html , not your JSON.

  • FastAPI introduces app.frontend() to fix route-order bug in SPA serving
  • app.frontend() separates routes into lowpriorityroutes for correct serving
  • New function distinguishes between client-side navigation and non-existent assets

More from Sunday 20 September →