I have inherited a WordPress project and am currently writing a script to export database tables in .csv format. The original designer stored a lot of user data for each user in the wp_usermeta table. Unfortunately, most of this information was optional, and in the case of additional NULL data, the row in the database simply does not exist. Example for users with the optional gender field:
umeta_id user_id meta_key meta_value 1 1 gender 1 2 1 phone 5555555555 3 1 address "123 alphabet lane" 4 2 phone 5555551234 5 2 address "123 alphabet way" 6 3 gender 2 ...
I do not have enough missing fields with .csv, or the formatting will look strange, so I need to check every user information for these missing fields and insert an empty line. Since I will iterate through tens of thousands of database rows, I was curious which method of assigning variables was the most efficient in terms of memory usage and runtime for this.
Method 1
if (empty($fetched[$field])) { $data[$field] = ''; } else { $data[$field] = $fetched[$field]; }
Method 2
$data[$field] = ''; if (! empty($fetched[$field]) { $data[$field] = $fetched[$field]; }
Method 3
$data[$field] = empty($fetched[$field]) ? '' : $fetched[$field];
Or are they all close enough that it really doesn't matter? Thanks in advance for any information you can offer!
source share