/    Sign up×
Community /Pin to ProfileBookmark

How to empty array or set to null

How do you emply an array or set it to null?

thanks,

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 10.2009 — [code=php]
// make it an empty array:
$myArray = array();

// completely get rid of the array:
unset($myArray);
[/code]
Copy linkTweet thisAlerts:
@damon2003authorNov 10.2009 — thanks that works.

By the way what is the difference between

$array1() and $array1[]

thanks,
Copy linkTweet thisAlerts:
@NogDogNov 10.2009 — [b]array()[/b] (no "$") is a call to the array() language construct, used to define the contents of an array. [b]$array1[][/b] references the next available index for array variable [b]$array1[/b]. So...
[code=php]
$array1 = array('test');
[/code]
...creates or overwrites $array1 with the specified array elements (or an empty array if no values are given), while...
[code=php]
$array1[] = 'test';
[/code]
...adds a new element to the array with value "test" and with the array index being the next available integer index for that array.
×

Success!

Help @damon2003 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.18,
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,
)...