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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:00:01+00:00 2026-06-12T03:00:01+00:00

I am trying to push new array item into existing array variable that has

  • 0

I am trying to push new array item into existing array variable that has items from database. What I want to do is add a new item named ‘Others’ at the end of this array and display it as select drop down in view which consists of all the items from database and at the end of this select the ‘Others’ item that I manually added in my controller.

Here is what I tried to do:

    $competition_all = Competition::all();
    $newCompete = array('name'=>'Others');
    array_push($competition_all, $newCompete);

    $this->competition_games = array('Competition');

    foreach ($competition_all as $competition_games) {
        $this->competition_games[$competition_games->name] = $competition_games->name;
    }

what it said is like this

Unhandled Exception

Message:

Trying to get property of non-object Location:

C:\xampp\htdocs\khelkheladi\khelkheladi\application\controllers\register.php
on line 104

In my database the Competition has this type of column structure

->id
->year
->place
->name
->created_at
->updated_at

in given order.

What I’m trying to do is without actually inserting an item in database, just statically show the others select item in select tag in view. How do I insert such new item without actually inserting it to database but to display in view only?

The output what i’m getting before by just retrieving database item is like this

<select>
  <option value="1">Value 1</option>
  <option value="2">Value 2</option>
  <option value="3">Value 3</option>
  <option value="4">Value 4</option>
</select> 

what I like to do is like this

<select>
  <option value="1">Value 1</option>
  <option value="2">Value 2</option>
  <option value="3">Value 3</option>
  <option value="4">Value 4</option>
  <option value="5">Others</option>
</select> 
  • 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-12T03:00:03+00:00Added an answer on June 12, 2026 at 3:00 am

    The "clean" way to do it would be to create an instance of Competition without committing it to the database, and repeat once more your cycle with the extra instance.

    However, here you appear to be just producing a list, so it ought to be enough to do a much quicker addition to the final list:

    // Empty array
    $this->competition_games = [ 0 => 'Others' ];
    
    foreach (Competition::all() as $game) {
        $this->competition_games[$game->id] = $game->name;
    }
    

    Using 0 (or -1) as the nonexistent Id.

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

Sidebar

Related Questions

I'm trying to push new data into an existing array $query : $query =
I am trying to use .push to put items into a javascript array. I
I'm trying to add a new item to an observable array when a button
I have been trying to add variables from a dropdown into an array using
I'm trying to get all categories and push them into my array , so
I'm trying to loop through a multidimensional array, and add a new sub array.
I am trying to push new values to an array, but when the values
I have an array that I'm removing items from but I'm keeping count of
Im trying push some data into a CRM system via an XML import. I
I am getting this error when I am trying push my files into heroku

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.