• You are not logged in. | Login

Post a reply

November 17, 2006 4:07 am

mambojim
Member
Ranks

question about array() and unset()

If I have an array like:

$_SESSION['items']= array('item1', 'item2', 'item3')

and I do:
unset($_SESSION['items'][1]) in order to remove 'item2'

Do the remaining values get re-indexed like:
$_SESSION['items'][0] = 'item1'
$_SESSION['items'][1] = 'item3'

If not, how do I achieve the above re-indexing?

Also, if the values are not re-indexed will count($_SESSION['items']) still equal 3?


 

 

November 23, 2006 1:33 pm

senjor_itc
Member
Ranks

Re: question about array() and unset()

1. Values not re-indexed. You must do the following to reindex values:

$_SESSION['items']= array('item1', 'item2', 'item3');
unset($_SESSION['items'][1]);
sort($_SESSION['items']);

2. count($_SESSION['items']) === 2.


 

 
  • Actions
  • Top
ITCrimea. Ukraine Web Development Company. Professional Developers and Web Designers Team
Custom Web Designs, Internet Applications, E-Commerce Websites, Interactive Sites, Database-Driven Sites and Services