RE: [PHP] How to get the key of a specific index of array?

From: Date: Tue, 18 Nov 2003 13:46:05 +0000
Subject: RE: [PHP] How to get the key of a specific index of array?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-170094@lists.php.net to get a copy of this message
> -----Oorspronkelijk bericht----- > Van: PhiSYS [mailto:phisys@netscape.net] > > How to get the key of a specific index of array? > > It seems that key($_POST[$i]) is a wrong syntax. > > I've worked around like this: > > $allkeys = array_keys($_POST); > $allvalues = array_values($_POST); > > for($I=3; $I < count($_POST); $I++) { > echo $allkeys[$I]; > echo $allvalues[$I]; > } > First of all, you said to use the first three values of the array for anoter reason .. well the, what I'd do is this: $FirstThree = array_splice($_POST, 0, 3); Which will give you the first three elements of the array, and leave you with a $_POST array you can do foreach with. Second, to manually loop through an array, use: http://nl.php.net/manual/en/function.prev.php http://nl.php.net/manual/en/function.next.php http://nl.php.net/manual/en/function.current.php http://nl.php.net/manual/en/function.reset.php http://nl.php.net/manual/en/function.end.php Third, don't rely on the order your array elements are given to you by post data. Rather just use foreach() and (ignore|do something else with) the key-value pairs you don't want for this thing. Fourth, I hope I'm not spoiling Jay Blanchard statement on how uncredibly great this online PHP Manual is since you could probably find all the answers to array related questions right here: http://nl.php.net/manual/en/ref.array.php And all you other answers around here: http://nl.php.net/docs.php and here http://www.google.com

« previous php.general (#170094) next »