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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:27:02+00:00 2026-05-25T20:27:02+00:00

Thanks guys. I was wrong about my way. Please don’t post anymore. I had

  • 0

Thanks guys. I was wrong about my way. Please don’t post anymore.

I had some trouble with my array.

I generate my array in this way:

private function _getMenuBar(){
    $data = array();
    $query = $this->db->query("SELECT * FROM df_menubar_table WHERE visible = 1 AND parent = -1 ORDER BY priority");
    foreach($query->result_array() as $row){
      $data[count($data)] = array(
        "menu" => array(
          "title" => $row['title'],
          "url" => $row['url'],
          "name" => $row['name'],
          "selected" => 0
        )
      );
    }
    return $data;
  }

As usual array will feed like

array[0] = menu => array(title,url,name,selected);

but I want to not define $data[**count($data)**] as index and define ‘menu’ as index. And CodeIgniter doesn’t support something like this for passing to views. Therefore I need to key be the menu.

It means:

array[0] = menu => array(title,url,name,selected);

To:

array[‘menu’] = array(title,url,name,selected);

BTW, I tried += but It just stored the last row.

Thanks.

Edit:

I tried your way it turned to this:

I tried it. But it turned to this:

array(1) {
  ["menu"]=>
  array(5) {
    [0]=>
    array(1) {
      ["menu"]=>
      array(4) {
        ["title"]=>
        string(8) "اصلی"
        ["url"]=>
        string(30) "http://localhost/dreamfactory/"
        ["name"]=>
        NULL
        ["selected"]=>
        int(0)
      }
    }
  • 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-25T20:27:03+00:00Added an answer on May 25, 2026 at 8:27 pm

    You need some type of unique identifier. Adding multiple items to array[‘menu’], with no unique identifier, will cause the last/newest item to overwrite the ones before. You can have an array set up like below.

     Array 1:
     Array (
       [menu] => Array (
         [0] => Array (
           [title] => Title
           [url] => URL
           [name] => Name
           [selected] => Selected
         )
       )
     )
    
     Array 2:
     Array (
       [0] => Array (
           [title] => Title
           [url] => URL
           [name] => Name
           [selected] => Selected
       )
     )
    

    The last one can be with or with out the menu item.

    Code will look like below (simplified)

     private function _getMenuBar(){
      $data = array();
      $query = $this->db->query("SELECT * FROM df_menubar_table WHERE visible = 1 AND parent = -1 ORDER BY priority");
      $countRows = 0;
      foreach($query->result_array() as $row){
       $data[$countRows] = array(
          "title" => $row['title'],
          "url" => $row['url'],
          "name" => $row['name'],
          "selected" => 0
        );
        $countRows++;
       }
      return $data;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

thanks guys.i managed to complete it.million thanks again specially for DAVID,WM-EDDIE and S.LOTT.also STACKOVERFLOW
Update: Thanks guys, I didn't realize it was very close to zero but not
I need to ask you guys/gals out there about a concept of website development
I have in my homework some question about data structure: I have elements which
Hey guys I'm new to rails. I'm practice what I've learned today about rails
** Preface: I don't know much about networking. If i described the set up
Do you guys see any problems with the way I handle errors in the
Hey Guys my goal for this multi dimensional array is to document the answers
Hey guys. I'm having this problem for 2 days now and I really don't
Thanks to all that responded to my previous thread. There is still a problem

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.