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 8798341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:04:36+00:00 2026-06-14T00:04:36+00:00

The code works perfect, but since I’m repeating myself (which I like to avoid

  • 0

The code works perfect, but since I’m repeating myself (which I like to avoid while programming), I was wondering if this could be written any shorter/better?

$start = getLocaleDate($item[0]['start_day']);
$start = $start['day_int'] . ' ' . $start['month_string'];
if ($item[0]['start_houre'] !== '00:00:00') {
    $houre = stripLeadingZero(substr($item[0]['start_houre'], 0, 2));
    $minute = substr($item[0]['start_houre'], 3, 2);
    $start .= ' at' . $houre . 'u' . $minute;
}

$end = getLocaleDate($item[0]['end_day']);
$end = $end['day_int'] . ' ' . $end['month_string'];
if ($item[0]['end_houre'] !== '00:00:00') {
    $houre = stripLeadingZero(substr($item[0]['end_houre'], 0, 2));
    $minute = substr($item[0]['end_houre'], 3, 2);
    $end .= ' at' . $houre . 'u' . $minute;
}
  • 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-14T00:04:38+00:00Added an answer on June 14, 2026 at 12:04 am

    Without changing any of the functionality, you could make it into a function:

    function getTime($item, $which) {
        $time = getLocaleDate($item[0][$which . '_day']);
        $time = $time['day_int'] . ' ' . $time['month_string'];
        if ($item[0][$which . '_houre'] !== '00:00:00') {
            $houre = stripLeadingZero(substr($item[0][$which . '_houre'], 0, 2));
            $minute = substr($item[0][$which . '_houre'], 3, 2);
            $time .= ' at' . $houre . 'u' . $minute;
        }
        return $time;
    }
    
    $start = getTime($item, 'start');
    $end = getTime($item, 'end');
    

    * It should be noted that this code doesn’t do any error checking/prevention though, so if there is no index 0 in the $item, you will have an error (same goes for $item[0]['start_day'], $item[0]['end_day'], etc). To handle a simple-case, you could add if (!isset($item[0])) return ''; to the beginning of the function, if it’s a concern.

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

Sidebar

Related Questions

I have this code to write to a file, it works perfect but I
I have developed a html css code. It works perfect on all browsers but
Using this code to zip a folder and it works perfect on small files
This code works well for displaying separate xml items in my main.xml. But is
This code works fine, but I'll want to handle exception if any thing goes
My code works perfect for files smaller than 45 Kb but when I upload
Following code works perfect and adds 1 and 2 values to the list, but
The following code works perfect with transitional doctype but a small bottom border appears
I have a jQuery code which works perfect on desktop browsers; $(span#checkbox_err).mouseout(function () {
I have the following sql statement, which works perfect and since I'm transferring everything

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.