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:clas

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745288531a4620713.html

相关推荐

  • 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:clas

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信