Pass an argument into a function to extract from array

I feel like this should be possible.

I have a function within my class which pulls a single row from my custom table:

class Get_Data{

public static function get_data_single_db()
{
global $wpdb;
$user_table_name = $wpdb->prefix . ‘custom_table’;
$results = $wpdb->get_results(
“SELECT *
FROM $user_table_name
WHERE unique_id = ‘$unique_id’;”
);

return $results;
}

The $results array contains 7 keys. At the moment, outside of the class I am using this to extract a single key value:

Get_Data::get_data_single_db()[0]->key;

This works, but out of curiosity, could something like this work better:

Get_Data::get_data_single_db($key)

and in the function:

public static function get_data_single_db($key)
…..
return $results->key

Read more here:: Pass an argument into a function to extract from array

Leave a Reply

Your email address will not be published. Required fields are marked *