最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Pass an argument into a function to extract from array

programmeradmin2浏览0评论

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
发布评论

评论列表(0)

  1. 暂无评论