Kristaps Gaidulis Kristaps Gaidulis - 1 year ago 110
PHP Question

PHP array returns displays wrong value

Must be something simple, but I have been struggling with this for a while.
I have PHP array

//Have array $arr which contains values from database
foreach($arr as $value){
$idToMatch = $value['id'];
$dateToCompare = $value['createdAt']->format('F j Y, g:i');


Now to check how my array looks i use

echo '<pre>'; print_r($createdAtArray); echo '</pre>';

which returns :
enter image description here

So I try to access my arrays value like this : $createdAtArray[0] and except to get January 1 2019, 12:00 but instead I get 'J' (First Letter in string)

After trying multiple options I found out that by accessing just $createdAtArray I get January 1, 2019, 12:00.

However I cant get values that I want. What am I doing wrong?

Answer Source

array push


 foreach($createdATArray as $key=>$row)

     echo $row['date'];
     echo $row['id'];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download