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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:11:35+00:00 2026-05-12T20:11:35+00:00

I am using a multi-dimensional associative array to keep track of monthly totals, then

  • 0

I am using a multi-dimensional associative array to keep track of monthly totals, then I want to loop through it using foreach and output the contents.

The totals for each inner array are kept in element 12, and only want each array to output if the total is > 0, except “Total”, which I want to output even if it is 0.

  foreach($yearspend as $key => $format)
  {
     // only show formats with any spend
     if($key == "Total" || $format[12] > 0)
     {
        echo "<tr><td>$key</td>";
        foreach($format as $value)
        {
           echo "<td>".number_format($value,2)."</td>";
        }
        echo "</tr>";
     }
  }

For some reason this outputs for inner array 0, even though [0][12] is 0.

Here is the output from print_r:

Array
(
    [0] => Array
        (
            [12] => 0
        )

    [Group] => Array
        (
            [12] => 0
        )

    [Total] => Array
        (
            [12] => 0
        )
)

Please can anyone help?

  • 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-05-12T20:11:35+00:00Added an answer on May 12, 2026 at 8:11 pm

    Try

     $key === "Total" ...
    

    When comparing a string and a number, PHP attempts to convert the string to a numeric type and then performs the comparison. The ‘===’ operator compares the value and type, so a string will never equal a number.

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

Sidebar

Related Questions

I am using a multi-dimensional dynamic array in delphi and am trying to figure
I am trying to create a multi dimensional array using this syntax: $x[1] =
I need to store a multi-dimensional associative array of data in a flat file
I'm using a multi dimensional array in php, I would like to know how
What is the most efficient way of setting values in C# multi-dimensional arrays using
As I am using for-loops on large multi-dim arrays, any saving on the for-loop
I am using a plugin that requires an array of associative rows as a
How do I initialize a multi-dimensional array of a primitive type as fast as
A legacy embedded system is implemented using a cooperative multi-tasking scheduler. The system essentially
I'm playing around with LinqToSQL using an existing multi-lingual database, but I'm running into

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.