0

I am trying to echo a variable inside a object array..

array(4) 
{ 
 [0]=> int(20) 
 [1]=> string(16) "Demo Blog Post 3" [2]=> string(753) "Lorem ipsum dolor sit" 
 [3]=> object(DateTime)#1 (3) 
  {
   ["date"]=> string(19) "2016-02-19 13:28:23" 
   ["timezone_type"]=> int(3) 
   ["timezone"]=> string(11) "Asia/Muscat" 
  } 
} 

I want the date object in this array... how can I get this... ?

 $times = $row[3]->date;     // Returning NULL
 echo count($times);         // 1
 $times = $row[3]['date'];   // Returning CodeBreak.

var_dump($row[3])

object(DateTime)#1 (3) {
  ["date"]=> string(19) "2016-02-19 13:28:23" 
  ["timezone_type"]=> int(3) 
  ["timezone"]=> string(11) "Asia/Muscat" 
 } 

var_dump(get_object_vars($row[3]))

array(3) 
{ 
  ["date"]=> string(19) "2016-02-19 13:28:23" 
  ["timezone_type"]=> int(3) 
  ["timezone"]=> string(11) "Asia/Muscat" 
} 

Thanks...

9
  • what you are getting for var_dump($row[3]); ? Commented Mar 3, 2016 at 7:00
  • @PrafullaKumarSahu Edited Question. Commented Mar 3, 2016 at 7:01
  • try $row[3]->date because your $row is a object! Commented Mar 3, 2016 at 7:02
  • Its already tried. see my question... its returning NULL Commented Mar 3, 2016 at 7:03
  • 2
    now try to get var_dump(get_object_vars ($row[3])['date'] ); Commented Mar 3, 2016 at 7:08

2 Answers 2

1

use get_object_vars this helps you to get the properties of the given object

like this

var_dump(get_object_vars ($row[3])['date'] );
Sign up to request clarification or add additional context in comments.

Comments

0

If you named your array $products, wouldn't you get date from $products[3]["date"]?

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.