Re: [PHP] How to get the key of a specific index of array?
Wouter Van Vliet [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] 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. Great! Thanks! I think it will be very useful. 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 Yes, I know these functions, but I'm still wondering if there's a DIRECT way to move an array's internal pointer to a specific position and/or key. 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. But if these required three keys are messed up into the $_POST array, Is there a direct way to shift off elements at a specified key or index to remove them from an array? (I mean without a batch process) Something like: array_shift($array, $index) which of course is incorrect Although now I know I can write a code to search for a key and then splice it out from $_POST into another one. Thanks! 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 Thanks... I'm reading the online manual and many other sites before posting to newsgroups, As you can see, I'm not an expert programer but just a beginner. I'm trying to make a lightweight any-form-to-email script. The first 3 keys of the associative array ($_POST) are recipient, reply_email and subject. All other NAMED form elements will be mailed with this format: FORM NAME (key): FORM VALUE (value) - PhiSYS -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How to get the key of a specific index of array?
On 19 November 2003 12:59, David Strencsev contributed these pearls of wisdom: Wouter Van Vliet [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] 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. Great! Thanks! I think it will be very useful. 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 Yes, I know these functions, but I'm still wondering if there's a DIRECT way to move an array's internal pointer to a specific position and/or key. As someone else said before, I feel you may be thinking in the wrong direction. If you could give us a couple of examples of data you might expect to see in your $_POST aray, and what you wish to produce from it -- e.g. a sample of the final results from the provided data -- we might be able to provide the *real* solution to your problem, not try to shoehorn it into what might be an inappropriate one. In short, give us (a) sample input and (b) desired output, and see what suggestions come up for getting from (a) to (b) -- you might be surprised at how different they are from what you expect! ;) Cheers! Mike -- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to get the key of a specific index of array?
PhiSYS wrote: How to get the key of a specific index of array? It seems that key($_POST[$i]) is a wrong syntax. $i is the key, key is the index. I think you are overcomplicating it. Tell us what you want to achieve and someone might come out with a better solution. Marek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How to get the key of a specific index of array?
[snip] How to get the key of a specific index of array? [/snip] http://us2.php.net/manual/en/function.array-keys.php That manualamazing, no? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How to get the key of a specific index of array?
-Oorspronkelijk bericht- Van: PhiSYS [mailto:[EMAIL PROTECTED] 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to get the key of a specific index of array?
PhiSYS wrote: How to get the key of a specific index of array? Sorry, but an index is they key. $foo = array(0 = Apples, 1 = Oranges, 2 = Grapes); $key = 2; $value = $foo[$key]; echo $value; //you would get Grapes //another way (maybe this is what you are after) while(list($key,$value) = each($foo)) { echo For key .$key. the value is .$value; } -- Burhan Khalid phplist[at]meidomus[dot]com http://www.meidomus.com --- Documentation is like sex: when it is good, it is very, very good; and when it is bad, it is better than nothing. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php