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

The Archive Base Latest Questions

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

In jQuery there is $.extend() function. That basically works like matching default settings with

  • 0

In jQuery there is $.extend() function. That basically works like matching default settings with input settings. Well, I want to use similar technique in PHP, but it seems, that there is no similar function. So I’m wondering: Is there a similar function as .extend(), but in PHP? If not then, what alternatives are there?

This is an example class and how I get this effect currently. I also added a comment, how I would wish to do this:

class TestClass {
    // These are the default settings:
    var $settings = array(
        'show' => 10,
        'phrase' => 'Miley rocks!',
        'by' => 'Kalle H. Väravas',
        'version' => '1.0'
    );
    function __construct ($input_settings) {
        // This is how I would wish to do this:
        // $this->settings = extend($this->settings, $input_settings);

        // This is what I want to get rid of:
        $this->settings['show'] = empty($input_settings['show']) ? $this->settings['show'] : $input_settings['show'];
        $this->settings['phrase'] = empty($input_settings['phrase']) ? $this->settings['phrase'] : $input_settings['phrase'];
        $this->settings['by'] = empty($input_settings['by']) ? $this->settings['by'] : $input_settings['by'];
        $this->settings['version'] = empty($input_settings['version']) ? $this->settings['version'] : $input_settings['version'];

        // Obviously I cannot do anything neat or dynamical with $input_settings['totally_new'] :/
    }
    function Display () {
        // For simplifying purposes, lets use Display and not print_r the settings from construct
        return $this->settings;
    }
}

$new_settings = array(
    'show' => 30,
    'by' => 'Your name',
    'totally_new' => 'setting'
);

$TC = new TestClass($new_settings);

echo '<pre>'; print_r($TC->Display()); echo '</pre>';

If you notice, that there is a totally new setting: $new_settings['totally_new']. That should just get included inside the array as $this->settings['totally_new']. PS: Above code outputs this.

  • 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-25T03:20:28+00:00Added an answer on May 25, 2026 at 3:20 am

    Try to use array_merge php function. Code:

    array_merge($this->settings, $input_settings);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that looks like this: jQuery.fn.menuFunc = function( settings ) {
I want to extend the ajax function so that whenever it is called an
Are there any jQuery 1.3 animation-transitions that work in both Firefox 3 and IE7?
Is there a jQuery project out there, that create on of these Password-strength-meters right
Is there any jquery plugin for implementing iGoogle style dashboard? So basically drag n
Is there a jquery plugin that when you hover over an icon etc. it
Is there a jQuery plugin or javascript library that supports a genie animation effect
I'm trying to pass a function as an option through a jquery plugin that
I am trying to override the jQuery ajax function to handle a default action
Today, my only pressing question about jQuery is about the when to use jQuery.extend()

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.