Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8686321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:48:53+00:00 2026-06-12T22:48:53+00:00

I have a dynamic array $v whose contents change according to a form being

  • 0

I have a dynamic array $v whose contents change according to a form being submitted. Some forms might have a date field and others may not. For all forms I’m using the same array $v to store values in a key=>value pair and then insert it into the table. So sometimes the array may look like

$v = array('patron_name'=>'some value',
           'place' => 'again some value',
           'pin' => 'blah blah')

and at other times it may look like

$v = array('joomla'=>'some value again',
           'date_applied' => '23/04/2012',
          )

As seen above, the contents vary from form to form. What I’m looking for is to first check if $v contains a value in the form of dd/mm/yyy and if it does, change it to yyyy-mm-dd format to insert into table. I can handle the conversion part, but I’m stuck at determining if $v contains a date or not.

So basically I’m intending to proceed in this way:

if(in_array('date in dd/mm/yyyy format', $v))
{
  // change it to yyyy-mm-dd
}
// and then insert into table
$flag = insert($tablename, $v);

Any help much appreciated. Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:48:54+00:00Added an answer on June 12, 2026 at 10:48 pm

    Instead of in_array, use preg_replace_callback. Pass the array to it and match for the date format pattern. If the pattern matches, replace it with the callback.

    Example (demo):

    $v = array(
        'joomla'=>'some value again',
        'date_applied' => '23/04/2012',
    );
    
    $result = preg_replace_callback('#^\d{1,2}/\d{1,2}/\d{4}$#', function($match) {
        return DateTime::createFromFormat('d/m/Y', $match[0])->format('Y-m-d');
    }, $v);
    
    print_r($result);
    

    On a sidenote, since Y-m-d contains the same values as d/m/Y, you don’t strictly need to use a callback but can just use preg_replace (demo):

    $result = preg_replace('#^(\d{1,2})/(\d{1,2})/(\d{4})$#', '$3-$2-$1', $v);
    

    Using a callback would allow you to use an arbitrary date format though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some sort of dynamic array in C++ where each element have their
I have dynamic array filled with bytes, which are read from .raw file with
I currently have the dynamic array: char *myData[500][10]; //myData is the name of an
i would like create a array of structure which have a dynamic array :
I have a 2D dynamic array. I enter a line of 0's after line
I have a struct with a dynamic array inside of it: struct mystruct {
Hi I need to make an dynamic array like this: I have a max
I have a code segment that generates a dynamic 3D array of random numbers
I have a dynamic array of strings, the elements of which I would like
I have a dynamic array. But initially I am not knowing the length of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.