WordPress get all DB table column value as array

[ad_1]

I have register a table on WordPress and assume the table name is my_table and so far it looks like below:

| id | name |
| — | ———- |
| 1 | apple |
| 2 | orange |
| 3 | watermelon |

How do I get all the value from name as an array like below?

$data = array( 'apple', 'orange', 'watermelon');

I have tried the below code but it just show/print the word Array


global $wpdb;

$table_name = $wpdb -> prefix . 'my_table';
$data = $wpdb -> get_results ( $wpdb -> prepare ( "SELECT name FROM $table_name" ) );

echo $data;

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer