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

  • Home
  • SEARCH
  • 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 8880491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:10:32+00:00 2026-06-14T20:10:32+00:00

Good evening I have a question here. i have two arrays: $duration_c[$k][$s]. it prints

  • 0

Good evening

I have a question here. i have two arrays: $duration_c[$k][$s]. it prints all ok

$duration_c[0][0]="19:30:00";
$duration_c[0][1]="00:10:00";

$duration_c[1][0]="00:30:00";
$duration_c[1][1]="00:20:00";

than to sum

$times=$duration_c[$k][$s];
function sum_the_time($times) {

  $seconds = 0;
  foreach ($times as $time)
  {
    list($hour,$minute,$second) = explode(':', $time);
    $seconds += $hour*3600;
    $seconds += $minute*60;
    $seconds += $second;
 }
  $hours = floor($seconds/3600);
  $seconds -= $hours*3600;
  $minutes  = floor($seconds/60);
  $seconds -= $minutes*60;
  // return "{$hours}:{$minutes}:{$seconds}";
  return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
} 
echo sum_the_time($times);

how to sum $duration_c[0][0]+$duration_c[0][1] and $duration_c[1][0]+$duration_c[1][1], and how to print?
there is error Invalid argument supplied for foreach()

  • 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-14T20:10:33+00:00Added an answer on June 14, 2026 at 8:10 pm

    you are sending only one value to sum_the_time function as $times=$duration_c[$k][$s];
    $times has only one value you can print and check what value is going to the function by writing like this

    $times=$duration_c[$k][$s];
    echo $times;
    

    use

    $times=$duration_c[$k];
    

    so that you can send array to your function and foreach will not give you error

    $times=$duration_c[$k]; // contains array of times
    function sum_the_time($times) {
    
      $seconds = 0;
      foreach ($times as $time)
      {
        list($hour,$minute,$second) = explode(':', $time);
        $seconds += $hour*3600;
        $seconds += $minute*60;
        $seconds += $second;
     }
      $hours = floor($seconds/3600);
      $seconds -= $hours*3600;
      $minutes  = floor($seconds/60);
      $seconds -= $minutes*60;
      // return "{$hours}:{$minutes}:{$seconds}";
      return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
    } 
    echo sum_the_time($times);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good evening fellow stackers, I have a mutex and threaded related question about //
Good Evening All, I have a textbox that needs to accept 14 digits plus
Good evening, here is what I am trying to achieve, I currently have a
Good evening everyone, I have a quick question on a homework assignment my class
Good evening, I have a quick question that should be pretty easy, but for
Good evening all! i have an Ajax call that loads 5 'echo's' from a
Good evening, I would like to have a navigation bar which is centralised to
Good evening, I have been trying to wrap my head about this, below, code
Good evening ladies and gentlemen, I have a problem with Java Swing that I
Good evening, In my app that I'm currently developing, I have a class that

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.