Tag Archives: PHP

Counting Rows Returned by an SQLite3 Query in PHP

Tested with PHP 5.3.1

Strangely, when running queries against an SQLite3 database, there is no obvious way to know how many rows were returned by a specific query. After much hunting, I found a solution in the PHP manual, of all places.

Let’s say we have a table with 4 columns (id, seed, name, score), with 3 rows. The rest you need to know is in the code comments, really. Read more »

Scaling/Blowing Up a Two-Dimensional Array in PHP

Tested with PHP 5.3.1

In an upcoming post (Sightlines, or: Drawing Virtual Lines in a Two-Dimensional PHP Array Using Bresenham’s Line Algorithm), I’ll explain why I need to scale/blow up an array to 10x it’s size. Until then, this code snippet might not seem so useful. But, most everything I have written thus far has been leading up to the aforementioned post, and this is certainly a part of it. Read more »

Two-Dimensional Array Slicing in PHP

Tested with PHP 5.3.1

The array_slice function in PHP is a handy way to copy a chunk of information from one array to second array. This is useful to examine or modify some interesting set of data without mucking about with your original set, or cutting down on the size and overhead of operations, because you’re running them against a more compact array.

The function works on two-dimensional arrays, but in an unexpected way. Read more »

Two-Dimensional Array Searching in PHP

Tested with PHP 5.3.1

PHP’s array_search function is great! No longer must we single-step through every element of an array to find what we’re looking for. Too bad it only works on single-dimension arrays.

Read more »