/    Sign up×
Community /Pin to ProfileBookmark

Convert variables passed to class, to array

Hi

I have a class where the passed variable has to be an array because I don’t know the number of variables sent to the class:

[code=php]
$object = new class;
$object->classarray = array($var1, $var2, $var3);
[/code]

Is it possible to get rid of the array passed to the class?
Something like this:

[code=php]
$object = new class;
$object->classarray = ($var1, $var2, $var3);
[/code]

And then “convert” the [I]classarray[/I] to a array inside the class?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 21.2010 — You would need to call a method instead of an object variable, where you could use the variable arguments functions.
[code=php]
public function setArray()
{
$this->classArray = func_get_args();
}
[/code]

Usage:
[code=php]
$object->setArray($var1, $var2, $var3);
[/code]
Copy linkTweet thisAlerts:
@dbkauthorNov 21.2010 — NogDog, your my savior!

Thanks a lot - it works like a charm!
×

Success!

Help @dbk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...