Avatar of JamesFrog
JamesFrog

asked on 

How do I remove empty elements from an array and then re-index the keys (if that's what they're called?)

Hi,

If have an array $_SESSION['finalHTML'] which when I execute the following code:

___________________________________________________________________
print_r ( $_SESSION['finalHTML'] );
___________________________________________________________________

outputs the following:

Array ( [1] =>lemons[2] =>apples[7] =>plums[8] => [9] => [10] =>banana)

I need to do two things to this array:

1) Firstly I need to remove the empty elements (in this case they are 8 & 9 but this will vary depending on where my scripts at:

e.g. Array ( [1] =>lemons[2] =>apples[7] =>plums[10] =>banana)

2) and now I need my array to be re-indexed so it's set up as follows:

Array ( [1] =>lemons[2] =>apples[3] =>plums[4] =>banana)

What two functions do I need to use to do this?

Thanks as always
James :-)
PHP

Avatar of undefined
Last Comment
JamesFrog
ASKER CERTIFIED SOLUTION
Avatar of Vel Eous
Vel Eous

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of JamesFrog
JamesFrog

ASKER

Tchuki,

Thanks, that seems to work fine - I didn't think it could be that simple :-0

Cheers
James
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo