Make WordPress Core

Changeset 56066


Ignore:
Timestamp:
06/27/2023 02:33:39 PM (11 months ago)
Author:
spacedmonkey
Message:

Database: Move the if statement outside of the loop.

In the foreach loop of last results, move the if statement outside of the loop. There is no need to check every element in the array for the output type. Do this once outside of the loop. For large database queries with lots of rows returned, this should improve PHP performance.

Props spacedmonkey, Cybr, johnbillion, costdev, joemcgill.
Fixes #56541.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wpdb.php

    r55994 r56066  
    31383138            // Return an integer-keyed array of...
    31393139            if ( $this->last_result ) {
    3140                 foreach ( (array) $this->last_result as $row ) {
    3141                     if ( ARRAY_N === $output ) {
     3140                if ( ARRAY_N === $output ) {
     3141                    foreach ( (array) $this->last_result as $row ) {
    31423142                        // ...integer-keyed row arrays.
    31433143                        $new_array[] = array_values( get_object_vars( $row ) );
    3144                     } else {
     3144                    }
     3145                } else {
     3146                    foreach ( (array) $this->last_result as $row ) {
    31453147                        // ...column name-keyed row arrays.
    31463148                        $new_array[] = get_object_vars( $row );
Note: See TracChangeset for help on using the changeset viewer.