Re: [PHP] Array questions...
On Wed, March 5, 2008 9:35 am, Robert Cummings wrote: No textbook, but here's some advice... Think of a variable like a house address for an actual house. 123 Maple Street An array is just an apartment building: 125 Maple Street, Unit 1 125 Maple Street, Unit 2 125 Maple Street, Unit 3 . . . When you want to talk about the whole array (building) you can use just the street address. If you want a specific unit, you have to add the [$unit] part. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Array questions...
On 05 March 2008 15:50, Jason Pruim advised: > On Mar 5, 2008, at 10:41 AM, Ford, Mike wrote: > >> (I was also wondering to myself whether you actually really, really >> wanted $txtNumArray = $_POST['txtNumArray'], but perhaps you can easily >> explain why not...?) > > It's a habit I picked up when I was in school and studied > Visual basic > for a semester... That way, I know for sure if I'm working with the > original text verses the text stored in the variable. > > Is there any reason not to do it the way I am? I'm completely self > taught (With the help of many people from here!) so I'm open to > suggestions about stuff like this :) I have no issue with your naming style -- I simply noted the assignment to $NumArray followed by many references to $txtNumArray, and wondered if in fact they shouldn't both be $txtNumArray. Of course, it may be that you're giving $txtNumArray a value elsewhere in your script, and $NumArray is for some other purpose entirely, but I couldn't help wondering ;) -- Mike Ford, Electronic Information Services Adviser, JG125, The Headingley Library, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 812 4730 Fax: +44 113 812 3211 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array questions...
I won't address the main issue of your question, since it looks like that has been solved. But I want to point out a few other things that might help you. Follow along below... Jason Pruim wrote: So for some reason, arrays always mess me up... I don't know what it is, but it just hasn't clicked yet... So I'm sure this is a simple question for someone who knows and understands arrays :) So with that being said here's the code I'm using: $self = $_SERVER['PHP_SELF']; $i="0"; if (isset($_GET['txtNum'])) { $numBox= $_GET['txtNum']; $_SESSION['num'] = $_GET['txtNum']; }else{ here you need to make sure that $_SESSION['num'] exists. If not you will get a E_NOTICE warning level error. So, you should have this } else if ( isset($_SESSION['num']) ) { $numBox = $_SESSION['num']; } And then follow up the previous thing with this else statement } else { echo 'no "num" set'; // AND / OR $numBox = 0; } echo "store box variable". $_SESSION['num']; echo << How many boxes? HTML; $NumArray= Array($_POST['txtNumArray[]']); echo <Route #Pieces in routeWeight of route TABLE; echo ""; Change this to "post" <-- spec says lower case on the value And, you could get rid of the echo and move it to the last line of the previous HEREDOC statement while($i < $numBox){ echo << Here you would use just value="txtNumArray[{$i}]" value="txtNumArray[$i]"> Here you would use just value="{$i}" Here you would use just value="txtPiecesArray[{$i}]" value="txtPiecesArray[$i]"> Here you would use just value="{$i}" Here you would use just value="txtWeightArray[{$i}]" value="txtWeightArray[$i]"> Here you would use just value="{$i}" HTML; $i++; } echo ""; The reason I would do the above, is to make sure that all three arrays are in sync. What I'm attempting to do, is grab the info out of txtNumArray[] and put it into the variable $numArray Sounds easy enough right? Well I've tried using $NumArray = Array($_POST['txtNumArray[]'); but that's not working... I've tried $NumArray = $_POST['txtNumArray[]']; which didn't work... and I've looked on the php manual, but they all assume you understand this stuff which I do not :) Anyone know what I'm doing wrong? Or could at least point me to some text like "Array's for Dummies"? :) -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com [EMAIL PROTECTED] -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array questions...
On Wed, 2008-03-05 at 10:53 -0500, Jason Pruim wrote: > On Mar 5, 2008, at 10:35 AM, Robert Cummings wrote: > > > > I think you want the following after performing a very cursory look at > > your sample. > > > > > > > $NumArray > >= isset( $_POST['txtNumArray'] ) > >? $_POST['txtNumArray'] > >: array(); > > > > ?> > > Mind if I ask why setting it that way would be bettter? Other then the > fact that it looks like it might possibly handle some of the errors > I'm getting right now because I don't have the arrays defined before > this? > > Or did I just answer my own question? It ensures you have an array in the event nothing was posted. I never just assume that I received data I was supposed to receive. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array questions...
On Mar 5, 2008, at 10:35 AM, Robert Cummings wrote: I think you want the following after performing a very cursory look at your sample. Mind if I ask why setting it that way would be bettter? Other then the fact that it looks like it might possibly handle some of the errors I'm getting right now because I don't have the arrays defined before this? Or did I just answer my own question? -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array questions...
On Mar 5, 2008, at 10:41 AM, Ford, Mike wrote: On 05 March 2008 15:34, Jason Pruim advised: Okay so I'm replying to my own post... And top posting to boot! :P Amazing what happens when you pull a few [] off for completness: $NumArray = Array($_POST['txtNumArray']); works as I wanted :) Are you sure?? Looks a bit suspect to me, since $_POST['txtNumArray'] will already be an array, and what you've got there turns it into an Array of Array. From your original message, I was about to suggest you wanted simply $NumArray = $_POST['txtNumArray']; and I still suspect that might be more the mark. I think you may be right :) I just changed it to that without any issues... Few less bytes :) (I was also wondering to myself whether you actually really, really wanted $txtNumArray = $_POST['txtNumArray'], but perhaps you can easily explain why not...?) It's a habit I picked up when I was in school and studied Visual basic for a semester... That way, I know for sure if I'm working with the original text verses the text stored in the variable. Is there any reason not to do it the way I am? I'm completely self taught (With the help of many people from here!) so I'm open to suggestions about stuff like this :) -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Array questions...
On 05 March 2008 15:34, Jason Pruim advised: > Okay so I'm replying to my own post... And top posting to boot! :P > > Amazing what happens when you pull a few [] off for completness: > > $NumArray = Array($_POST['txtNumArray']); > > works as I wanted :) Are you sure?? Looks a bit suspect to me, since $_POST['txtNumArray'] will already be an array, and what you've got there turns it into an Array of Array. From your original message, I was about to suggest you wanted simply $NumArray = $_POST['txtNumArray']; and I still suspect that might be more the mark. (I was also wondering to myself whether you actually really, really wanted $txtNumArray = $_POST['txtNumArray'], but perhaps you can easily explain why not...?) -- Mike Ford, Electronic Information Services Adviser, JG125, The Headingley Library, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 812 4730 Fax: +44 113 812 3211 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array questions...
On Wed, 2008-03-05 at 10:28 -0500, Jason Pruim wrote: > So for some reason, arrays always mess me up... I don't know what it > is, but it just hasn't clicked yet... So I'm sure this is a simple > question for someone who knows and understands arrays :) > > So with that being said here's the code I'm using: > > $self = $_SERVER['PHP_SELF']; > $i="0"; > if (isset($_GET['txtNum'])) { > $numBox= $_GET['txtNum']; > $_SESSION['num'] = $_GET['txtNum']; > }else{ > $numBox = $_SESSION['num']; > } > echo "store box variable". $_SESSION['num']; > echo << > How many boxes? > > > HTML; > > $NumArray= Array($_POST['txtNumArray[]']); > > echo << Weight of 100 pieces: name="txtPieceWeight"> > Route #Pieces in route th>Weight of route > > TABLE; > echo ""; > while($i < $numBox){ > echo << > >value="txtNumArray[$i]"> > > >value="txtPiecesArray[$i]"> > > >value="txtWeightArray[$i]"> > > > HTML; > $i++; > > } > echo ""; > > > What I'm attempting to do, is grab the info out of txtNumArray[] and > put it into the variable $numArray Sounds easy enough right? Well I've > tried using $NumArray = Array($_POST['txtNumArray[]'); but that's not > working... I've tried $NumArray = $_POST['txtNumArray[]']; which > didn't work... and I've looked on the php manual, but they all assume > you understand this stuff which I do not :) > > Anyone know what I'm doing wrong? Or could at least point me to some > text like "Array's for Dummies"? :) I think you want the following after performing a very cursory look at your sample. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array questions...
Okay so I'm replying to my own post... And top posting to boot! :P Amazing what happens when you pull a few [] off for completness: $NumArray = Array($_POST['txtNumArray']); works as I wanted :) Anyone have any texts that could help me get a better grasp on arrays though? :) On Mar 5, 2008, at 10:28 AM, Jason Pruim wrote: So for some reason, arrays always mess me up... I don't know what it is, but it just hasn't clicked yet... So I'm sure this is a simple question for someone who knows and understands arrays :) So with that being said here's the code I'm using: $self = $_SERVER['PHP_SELF']; $i="0"; if (isset($_GET['txtNum'])) { $numBox= $_GET['txtNum']; $_SESSION['num'] = $_GET['txtNum']; }else{ $numBox = $_SESSION['num']; } echo "store box variable". $_SESSION['num']; echo << How many boxes? HTML; $NumArray= Array($_POST['txtNumArray[]']); echo << Weight of 100 pieces: name="txtPieceWeight"> Route #Pieces in routeth>Weight of route TABLE; echo ""; while($i < $numBox){ echo << value="txtNumArray[$i]"> value="txtPiecesArray[$i]"> value="txtWeightArray[$i]"> HTML; $i++; } echo ""; What I'm attempting to do, is grab the info out of txtNumArray[] and put it into the variable $numArray Sounds easy enough right? Well I've tried using $NumArray = Array($_POST['txtNumArray[]'); but that's not working... I've tried $NumArray = $_POST['txtNumArray[]']; which didn't work... and I've looked on the php manual, but they all assume you understand this stuff which I do not :) Anyone know what I'm doing wrong? Or could at least point me to some text like "Array's for Dummies"? :) -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com [EMAIL PROTECTED] -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Array questions...
So for some reason, arrays always mess me up... I don't know what it is, but it just hasn't clicked yet... So I'm sure this is a simple question for someone who knows and understands arrays :) So with that being said here's the code I'm using: $self = $_SERVER['PHP_SELF']; $i="0"; if (isset($_GET['txtNum'])) { $numBox= $_GET['txtNum']; $_SESSION['num'] = $_GET['txtNum']; }else{ $numBox = $_SESSION['num']; } echo "store box variable". $_SESSION['num']; echo << How many boxes? HTML; $NumArray= Array($_POST['txtNumArray[]']); echo << Weight of 100 pieces: name="txtPieceWeight"> Route #Pieces in routeth>Weight of route TABLE; echo ""; while($i < $numBox){ echo << value="txtNumArray[$i]"> value="txtPiecesArray[$i]"> value="txtWeightArray[$i]"> HTML; $i++; } echo ""; What I'm attempting to do, is grab the info out of txtNumArray[] and put it into the variable $numArray Sounds easy enough right? Well I've tried using $NumArray = Array($_POST['txtNumArray[]'); but that's not working... I've tried $NumArray = $_POST['txtNumArray[]']; which didn't work... and I've looked on the php manual, but they all assume you understand this stuff which I do not :) Anyone know what I'm doing wrong? Or could at least point me to some text like "Array's for Dummies"? :) -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com [EMAIL PROTECTED]
AW: [PHP] Array questions...
hi leon, > > Hello, > > Assume I have the following array: > > $array = array ( > "apple" => "cherry", > "foo" => "bar", > "wom" => "bat" > ); > > How could I easy remove the key and the value of the key > "foo" from that > array? > unset ($array[foo]); > Also, what is the best (and quickest) way to add a key with a > value to the > end of this array? > $array[newkey]=newvalue; > Thanks in advance, > > Leon Mergen > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Array questions...
Hello, Assume I have the following array: $array = array ( "apple" => "cherry", "foo" => "bar", "wom" => "bat" ); How could I easy remove the key and the value of the key "foo" from that array? Also, what is the best (and quickest) way to add a key with a value to the end of this array? Thanks in advance, Leon Mergen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php