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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:51:36+00:00 2026-06-08T07:51:36+00:00

I have encountered a problem when trying to add values to an array through

  • 0

I have encountered a problem when trying to add values to an array through a foreach loop.
Basically I have this form where there’s a bunch of topics that the user can click ‘like’ or ‘dislike’ on with two radio-buttons per topic. I then want to collect the “likes” and the “dislikes” in two separate arrays, and insert them into a database, but something I don’t do correct.
Here is a sample from the HTML code:

Action movies  Like<input type="radio" name="1" value="1" />  Dislike<input type="radio" id="2" name="1" value="2" />

And the PHP code:

if (isset($_POST['submit'])) {
    $likes = array();
    $dislikes = array();

    foreach($_POST as $key => $value) {

        /* $key is the name of the object an user can click "like" or "dislike" on, $value   
        is either 'like', which is equal to '2' or 'dislike', equal to '1' */
        if ($value > 1) { array_push($likes, $key); } else { array_push($dislikes, $key); 
    }
} 
echo 'The object(s) the user likes: ' . $likes . ' , 
       and the object(s) the user dislikes: ' . $dislikes;

I however receive this:

“The object(s) the user likes: Array , and the object(s) the user dislikes: Array”

I’m sure it’s just some stupid mistake I make here. I have googled this quite a lot but I have not been able to find any solution that helps me.

  • 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-08T07:51:38+00:00Added an answer on June 8, 2026 at 7:51 am

    An array when cast to a string will simply be output as the string "Array". If you want to output each element in the array, loop through them or use something like join:

    echo join(', ', $likes);
    

    array_push is working just fine.

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

Sidebar

Related Questions

I have encountered a problem when I was trying to add/post a data to
I have encountered this problem today and I don't have an explanation for it.
I've encountered an curious problem while trying to use some objects through JSNI in
I'm diving into EMF now, and have encountered the following problem: I'm trying to
I have encountered a list of errors when i was trying to execute this
I have encountered a problem when trying to select data from a table in
I'm trying to solve the following real-life problem you might have encountered yourselves: You
I have encountered a problem with creating a thumbnail from an uploaded image file,
I have encountered a problem in one of my Java projects, which causes bugs.
I have encountered a problem twice now whereby a producer thread produces N work

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.