RE: Add element

This is a discussion on RE: Add element within the PHP General forums, part of the PHP Programming Forums category; Warning ! Don't add one to your key ($j++) in this case. The "count()" method count ( :) ) return the ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-29-2003
Chris Sherwood
 
Posts: n/a
Default RE: Add element

Warning ! Don't add one to your key ($j++) in this case. The "count()"
method count ( :) ) return the number of existing keys in the $chk
array. You'll make hole in your array if you do this :

$arr[0] = "toto";

count($arr) => 1;

$arr[1] = "tata";

count($arr) => 2;

$arr[count[$arr]++] = "titi"; => $arr(0=>toto, 1=>tata, 3=>titi) (no
2=>)

Prefer array_push($arr, ...)

Cordialement,
Jean-Philippe BENARD
Consultant STERIA Infogérance
(jean-philippe.benard-renexter@renault.com)


Thanks for catching that Jean

:| damn I hate monday mornings
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:34 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0