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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:06:25+00:00 2026-05-11T19:06:25+00:00

I program in PHP mostrly and Ruby sometimes I happen to be in need

  • 0

I program in PHP mostrly and Ruby sometimes I happen to be in need of a way to implements those “hash arguments” into my PHP funcions (Like, say, an HTML select helper)

draw_select :name => :id, :onclick => 'alert(this.value)'

The problem in PHP is that I would have to define an argument order to implement many possible attributes.

I have been thinking of just define 1 string argument and use json_decode() so i can pass arguments like this:

draw_select("'name': 'id', 'onclick': 'alert(this.value)' ")

the definition would be as follows:

function draw_select($string) {
// use json_decode here and pass them as variables
}

Do you know a smarter way to do this.. or you think that triying to to this in PHP does actually makes any sense at all?

Edited to add: I’m looking for a ‘alternative’ alternative to just pass a signle array as an argument like function(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-11T19:06:26+00:00Added an answer on May 11, 2026 at 7:06 pm

    PHP definitely is lacking some sugar in this aspect. I do a lot of Python also and I dearly miss named arguments when using PHP. With PHP, however, whenever I have a function that will need to accept a multitude of options I simply accept one or two required/important arguments, and an array for the rest:

    function draw_select($name, $options = array(), $html_options = array()) {
    
    }
    

    This is the way libraries like CodeIgniter and CakePHP handle the same <select> scenario.

    Personally, using JSON in this situation brings no real benefit when PHP’s associative arrays are so powerful. Just stick to what the language gives you, and this is the way to do it with PHP.

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

Sidebar

Ask A Question

Stats

  • Questions 201k
  • Answers 201k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer May not be a good idea: Warnings: 1) Disconnect: What… May 12, 2026 at 8:13 pm
  • Editorial Team
    Editorial Team added an answer You should never call dealloc on anything other than super.… May 12, 2026 at 8:13 pm
  • Editorial Team
    Editorial Team added an answer As a general rule, don't ever compile parts of your… May 12, 2026 at 8:13 pm

Related Questions

I was looking for a portable script or command line program that can synchronize
I program mostly in PHP and have a site along with other samples in
I'm writing a web interface to MySQL that executes a couple queries and returns
I was trying to separate my DAL from my Business Layer, and in doing

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.