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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:34:13+00:00 2026-05-16T07:34:13+00:00

I could not figure out how to pass a variable number of variables into

  • 0

I could not figure out how to pass a variable number of variables into a function. I thought passing in an array and using the array keys for the variables names could replace the need to pass extra variables into the function, and it worked (I’m sure there is a better way to accomplish this, suggestions welcome). However, I can’t seem to get the keys out of the array inside the function.

The array:

  $parameters[day] = 1;
  $parameters[month] = 8;
  $parameters[year] = 2010; 

Inside the function:

foreach(key($parameters) as $key)
{
   print($key);
   print("<br>");
}

The code inside the function retuns a warning: Invalid argument supplied for foreach(). How can I pull the keys out of the array?

  • 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-16T07:34:14+00:00Added an answer on May 16, 2026 at 7:34 am

    You can use PHP’s array_keys function to grab the keys, like so:

    foreach(array_keys($parameters) as $paramName)
      echo $paramName . "<br>";
    

    Or, you can run through the array using a special foreach which allows you to separate the key and value for every element, like so:

    foreach($parameters as $paramName => $value)
      echo $paramName . "<br>";
    

    Also, make sure that you are using a "string" (with quotes) or integer (like 1337) as your key, like so:

    $parameters["day"] = 1;
    $parameters["month"] = 8;
    $parameters["year"] = 2010;
    

    OR if you want to get fancier:

    $parameters = array(
      "day" => 1,
      "month" => 8,
      "year" => 2010
    );
    

    Your code should look like:

    $parameters = array(
      "day" => 1,
      "month" => 8,
      "year" => 2010
    );
    foreach($parameters as $paramName => $paramValue)
      echo $paramName . "<br>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to parse a SQL query into an array. I could not figure
I could not figure out how to get the white fill for this ggplot2
i just could not figure out how i will put my data on a
I'm trying to play with inter-process communication and since I could not figure out
I am looking at the query syntax . and i could not figure out
A really simple question but I could not figure it out... I tried to
it looks very basic thing but i could not figure it out. var email
I'm not seeing the error and was hoping someone could figure it out: public
I have a quick question that I could not figure out in the docs
well i have most probably an extremly stupid problem but could not figure it

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.