1

This is how looks my var_dump variable.

object(stdClass)#879 (3) {
      ["row"]=>
      array(1) {
        ["option_id"]=>
        string(2) "20"
      }
      ["rows"]=>
      array(1) {
        [0]=>
        array(1) {
          ["option_id"]=>
          string(2) "20"
        }
      }
      ["num_rows"]=>
      int(1)
    }

I need to get option_id in this case option_id = 20 e.g. $option_id = 20

When I try this $variable['row']['option_id'] I get null value.

5
  • $variable->row->option_id Commented Nov 8, 2015 at 11:41
  • I try this, but now I get blank field. Commented Nov 8, 2015 at 11:44
  • 2
    Does this work? $variable->row['option_id']; Commented Nov 8, 2015 at 11:46
  • What do you see when you do var_dump($variable->row); Commented Nov 8, 2015 at 11:52
  • Now I going right way, with var_dump($variable->row['option_id']) I get string(2) "20" Commented Nov 8, 2015 at 11:55

1 Answer 1

1

The variable is an object of stdClass, so you have to access the properties instead of an index. For example:

$variable->num_rows

If you want to get the option_id, you have to use this (combine object and array syntax):

$option_id = $variable->row["option_id"];

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.