0

How can I properly format or update a date_created value inside an array so after I will have the same array but with some modified values in it ?

I want to format a date_created values with this function date("D, d F Y, H:i:s", strtotime($date_created));

Here is the result of dumped array - var_dump($query):

array
  0 => 
    array
      'id' => string '2' (length=1)
      'title' => string 'Title 2' (length=55)
      'date_created' => string '2011-03-09 08:04:14' (length=19)
  1 => 
    array
      'id' => string '1' (length=1)
      'title' => string 'Title 2' (length=57)
      'date_created' => string '2011-08-14 18:34:04' (length=19)

1 Answer 1

2

All you'll have to do is iterate over the array, change the values and replace the sub array with the original in the same index.

foreach($query as $key => $subArray){
  $subArray['date_created'] = date("D, d F Y, H:i:s", strtotime($subArray['date_created']));
  $query[$key] = $subArray['date_created'];
}
Sign up to request clarification or add additional context in comments.

4 Comments

And one question - what's wrong with my question ? Why I get minus ?
Well I'm not the voter so I can't say for sure why... But perhaps it is because this is a relatively simple task - to iterate over an array, and you did not show what you have tried already to resolve this... People want to know that you put some effort into your post...
Oh I see now, I'am sorry, but my english is at very poor level and I didn't know how to explain it. If I ever know the meaning of "iterate" before, I think it will be easier to find the answer. Thanks a lot again Lix.
No problem! happy to help! Don't feel bad about it, its only the opinion of one person :)

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.