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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:36:05+00:00 2026-06-16T04:36:05+00:00

This is making me crazy, because I need E_ALL turned on for other reasons.

  • 0

This is making me crazy, because I need E_ALL turned on for other reasons. I can’t get rid of this bug.

Here is my function:

public static function getFileCatsString($categories)
{
    if (empty($categories)) {
        return '';
    }
    $cats = self::getFileCats();

    $file_cats_string = '';
    $categories_array = explode(',',$categories);
    foreach($categories_array as $k=>$category_id) {
        $file_cats_string.=$cats[$category_id].', ';
    }
    $file_cats_string = rtrim($file_cats_string, ', ');
    return($file_cats_string);
}

Categories are stored in keyed array: [id]=>[string]

$categories that gets passed is a string of category_ids (long story as to why that is)

the getFileCats() method gets a list of all available categories.

So we explode the commad list to create an array, and then we loop through that array. I simply want to create, a string of category labels when I’m given a string of category ids. PHP returns this warning:

Notice: Undefined index: Array in Documents.php on line 40

Line 40 is:

      $file_cats_string.=$cats[$category_id].', ';

So obviously the undefined index is $cats[$category_id]. But here’s where it gets weird.

If I use a die() statement and echo out $cats[$category_id] I indeed get a string, not an array.

By the way, here is the output of each of the three key pieces of data with a die() statement put at the top of the foreach loop.

$categories_array:

Array ( [0] => 2 )

$cats:

Array ( [9] => Category 19 [8] => Category 8 [7] => Category 7 [6] => Another String I Changed For Privacy [5] => AED Sales [4] => Preceptor Folder [3] => Education Brochures [2] => Forms [1] => Guidelines and Policies )

$cats[$category_id]

Forms

$category_id

2

It gets weirder though. It says that the index is an array (which would indeed be a problem), so I tried putting:

        if (is_array($category_id)) {
            die(print_r($categories_array, true) . '<br />' . print_r($cats, true) . '<br />' . $cats[$category_id] . '<br />' . $category_id);
        }

to see if I could identify a piece of defending data, but it never dies. So what in the heck is going on?! (I have a sneaky suspicion that the answer is going to be forehead-slappingly simple.)

  • 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-16T04:36:06+00:00Added an answer on June 16, 2026 at 4:36 am

    The error is easier to understand knowing the fact that converting any array in PHP to a string results in the string:

    "Array"
    

    (this is also outlined in Type Juggling in the PHP manual)

    Exactly that happens in line 40:

    $file_cats_string .= $cats[$category_id] . ', ';
                               ^^^^^^^^^^^^
    

    The variable $category_id at that point is an array. Fix that. Valid array indexes/keys are integer numbers or strings but not arrays.

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

Sidebar

Related Questions

Ok this is really making me crazy and I need some help. I have
I'm making this method retrieve records from the Data Base. As you can see
I'm making this little program because I was bored and I ran across this
I'm making this little project with fwrite (long story, and I can't use DB's).
This problem is making me crazy. Actually I have multiple problems. First one: Why
This is making me crazy... I'm trying to have a custom WCF auth token
This is making me crazy. Is there a way to fire a mouseleave jquery
This is making me a little crazy. I'm trying to register some NSUserDefaults in
I've got this simple problem that is really making me crazy. I've got a
This problem is making me a bit crazy. I have something like this <h3>Feeds

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.