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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:53:11+00:00 2026-05-28T22:53:11+00:00

in my class i have an array defined like this class t { var

  • 0

in my class i have an array defined like this

class t {
    var $settings = array();
}

I will have these settings used quite a lot, so instead of writing $this->settings['setting'] all over the place I wanted to deploy a function that automatically defines these settings in local variables.

private function get_settings () {

            $array = $this->settings['array'];
            $foreign_key = $this->settings['foreign_key'];
            $limit = $this->settings['limit'];
            $tableclassid = $this->settings['tableclassid'];
            $pager = $this->settings['pager'];
            $container = $this->settings['container'];
            $extracolumn = $this->settings['extracolumn'];
    }

now, what I want to do is to get these variables and use them in another function within class. In example

public function test () {
     $this->get_settings();
     return $foreign_key;
}

and I want it to return $this->settings['foreign_key']

is there a way to do this? Or do I have to clutter all the functions with that block of code get_settings() has?

I appreciate the help.. thanks 🙂

  • 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-28T22:53:11+00:00Added an answer on May 28, 2026 at 10:53 pm

    Use the built-in extract() function, which extracts an array into individual variables in the current scope.

    extract($this->settings);
    

    If you need modifications to these local variables to be reflected in the original array, extract them as references.

    extract($this->settings, EXTR_REFS);
    

    I can’t say I would prefer to use this method myself though, or even recommend that you do it. Inside of a class, it is much more readable and understandable to keep them in the array property. In general, I never actually use extract().

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

Sidebar

Related Questions

I have an array of function callbacks, like this: class Blah { private var
Lets say I have a class like this: Class User { var $id var
I have 4 classes, one Database helper and 3 defined like this: abstract class
I have a generic class defined like this class MyGenericClass<T> where T : ICompareable
Suppose I have an array of a objects of user defined class. Wanted to
I have a class that contains an array. I want this array to be
I have defined a class in C++ which holds an array of scalars of
I have custom attribute defined like so: [AttributeUsage(AttributeTargets.Field)] public class EnumDisplayAttribute : Attribute {
I have a simple preference screen defined like this <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android> <PreferenceCategory android:title=Security> <CheckBoxPreference
I have a class that should look something like this: class Family_Type1 @people =

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.