从 Wordpress $wpdb->get_results 创建关联数组 [英] Creating an associative array from Wordpress $wpdb->get_results

查看:26
本文介绍了从 Wordpress $wpdb->get_results 创建关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是漫长的一天,出于某种原因,我完全无法理解...

It's been a long day and for some reason this is totally eluding me...

我的 Wordpress 数据库请求如下所示:

My Wordpress database request looks like this:

$results = $wpdb->get_results($sql);

输出看起来像这样

Array ( [0] => stdClass Object ([id] => 2 [organisation] => Company 2 ) 
        [1] => stdClass Object ([id] => 1 [organisation] => Company 1 ) 
)

我需要把它变成一个看起来像这样的数组:

I need to turn it into an array that looks like this:

Array ([1] => Company 1, [2] => Company 2)

这一定很简单,但由于某种原因我看不到它......感谢任何指点......

This must be dead easy, but I just can't see it for some reason...Grateful for any pointers...

推荐答案

$array = array();
foreach ($results as $res){
    $array[] = $res->organisation;
}

这篇关于从 Wordpress $wpdb->get_results 创建关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆