Re: add element to an array

From: Date: Mon, 29 Sep 2003 14:28:03 +0000
Subject: Re: add element to an array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-164248@lists.php.net to get a copy of this message
<-- snip --> > Hi, I want to add a new element to an array in php, is the following way the > correct way? assuming that $chk is an array and $ID contains a value. > > > $j = count($chk); > $j++; > $chk[$j] = $ID; <-- snip --> Yes that is one method of doing it. another method of adding an element to an array is by using array_push syntax is array_push($array,$vartoadd); there is also a keyed method but I am not 100% familiar with it and still getting the hang of it. Chris

« previous php.general (#164248) next »