How to print a string array on the screen?

1

How do I print this SQL query on the screen as a string?

$current_user = wp_get_current_user();

$resultado = $wpdb->get_results( "SELECT meta_value FROM $wpdb->usermeta WHERE user_id = '$current_user->ID' AND meta_key = '_jm_candidate_field_clocknow_user_btn'" );

This query is returning the following result:

Array ( [0] => stdClass Object ( [meta_value] => value_1 ) ) 

I would like to only display the value value_1 .

    
asked by anonymous 01.02.2017 / 18:29

1 answer

4

As the message itself says:

Array ( [0] => stdClass Object ( [meta_value] => value_1 ) ) 

Its $resultado variable is of type Array , containing a value in the zero position, of type stdClass , which has a meta_value attribute. To access it, we must first retrieve its object:

$resultado[0]

With the object, we can accept its attribute through the -> operator, as below:

$resultado[0]->meta_value;

If you want to do some operation with this value, it is more informative to store it in a variable:

$value = $resultado[0]->meta_value;

Here, your variable will have the value value_1 , following the example given in the question.

    
01.02.2017 / 18:43