RE: [PHP] global array
Jeff Burcher j...@allredmetal.com hat am 14. Juni 2012 um 14:23 geschrieben: You're a genius!! Thank you. Uppercase 'R', sheesh. PHP is sooo picky. I worked for two days trying to figure that one out. Anyway, for future reference, you can pass the entire array as a variable like that?? and do you know if the '+=' statement will create an array entry if one doesn't exist? If you are using a higher loglevel, you'll get a notice for a not existing array key. In the othercase $array[$mykey] += 1; will work without notice. But as the key does not exist, the value will be null and right now I am not sure what null + 1 evaluates to? Well, works maro@marco-behnke:~$ php -a Interactive shell php $array = array(); php $array['foo'] += 1; PHP Notice: Undefined index: foo in php shell code on line 1 PHP Stack trace: PHP 1. {main}() php shell code:0 php var_dump($array); array(1) { [foo]= int(1) } BUT I stronly recommend not to do that. make it this way: $array[$mykey] = array_key_exists($mykey, $array) ? $array[$mykey] += 1 : $array[$mykey] = 1; or better: if (array_key_exists($mykey, $array)) { $array[$mykey] += 1; } else { $array[$mykey] = 1; } Thanks, Jeff Burcher - IT Dept Allred Metal Stamping PO Box 2566 High Point, NC 27261 (336)886-5221 x229 j...@allredmetal.com -Original Message- From: ma...@behnke.biz [mailto:ma...@behnke.biz] Sent: Thursday, June 14, 2012 8:04 AM To: php-general@lists.php.net; j...@allredmetal.com Subject: Re: [PHP] global array Jeff Burcher j...@allredmetal.com hat am 14. Juni 2012 um 13:55 geschrieben: function Part_BOM($PartID, $need, $phase) { global $Invreq; uppercase R !!! And much better is adding it as another parameter and inject it: function Part_BOM($PartID, $need, $phase, $InvReq) { } // call it Part_BOM(..., ..., ..., $InvReq); And please read about foreach() and what you can do with it. -- 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 Marco Behnke Dipl. Informatiker (FH), SAE Audio Engineer Diploma Zend Certified Engineer PHP 5.3 Tel.: 0174 / 9722336 e-Mail: ma...@behnke.biz Softwaretechnik Behnke Heinrich-Heine-Str. 7D 21218 Seevetal http://www.behnke.biz -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global array
Jeff Burcher j...@allredmetal.com hat am 14. Juni 2012 um 13:55 geschrieben: function Part_BOM($PartID, $need, $phase) { global $Invreq; uppercase R !!! And much better is adding it as another parameter and inject it: function Part_BOM($PartID, $need, $phase, $InvReq) { } // call it Part_BOM(..., ..., ..., $InvReq); And please read about foreach() and what you can do with it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] global array
You're a genius!! Thank you. Uppercase 'R', sheesh. PHP is sooo picky. I worked for two days trying to figure that one out. Anyway, for future reference, you can pass the entire array as a variable like that?? and do you know if the '+=' statement will create an array entry if one doesn't exist? Thanks, Jeff Burcher - IT Dept Allred Metal Stamping PO Box 2566 High Point, NC 27261 (336)886-5221 x229 j...@allredmetal.com -Original Message- From: ma...@behnke.biz [mailto:ma...@behnke.biz] Sent: Thursday, June 14, 2012 8:04 AM To: php-general@lists.php.net; j...@allredmetal.com Subject: Re: [PHP] global array Jeff Burcher j...@allredmetal.com hat am 14. Juni 2012 um 13:55 geschrieben: function Part_BOM($PartID, $need, $phase) { global $Invreq; uppercase R !!! And much better is adding it as another parameter and inject it: function Part_BOM($PartID, $need, $phase, $InvReq) { } // call it Part_BOM(..., ..., ..., $InvReq); And please read about foreach() and what you can do with it. -- 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
Re: [PHP] global array
Yes - PHP is very picky. Hence I never capitalize anything! I use underscores to make varnames more understandable, as in $inv_req -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global array
On 6/14/2012 12:49 PM, Jim Giner wrote: Yes - PHP is very picky. Hence I never capitalize anything! I use underscores to make varnames more understandable, as in $inv_req There is another nice custom e.g. $invReg it's easy to read and it doesn't conflict with PHP syntax for some functions e.g., in_aray(). and defines DOCUMENT_ROOT -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global array
Al n...@ridersite.org wrote in message news:6b.c0.39100.4ef1a...@pb1.pair.com... On 6/14/2012 12:49 PM, Jim Giner wrote: Yes - PHP is very picky. Hence I never capitalize anything! I use underscores to make varnames more understandable, as in $inv_req There is another nice custom e.g. $invReg it's easy to read and it doesn't conflict with PHP syntax for some functions e.g., in_aray(). and defines DOCUMENT_ROOT And what is that custom? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global array
On Thu, 2012-06-14 at 15:13 -0400, Jim Giner wrote: Al n...@ridersite.org wrote in message news:6b.c0.39100.4ef1a...@pb1.pair.com... On 6/14/2012 12:49 PM, Jim Giner wrote: Yes - PHP is very picky. Hence I never capitalize anything! I use underscores to make varnames more understandable, as in $inv_req There is another nice custom e.g. $invReg it's easy to read and it doesn't conflict with PHP syntax for some functions e.g., in_aray(). and defines DOCUMENT_ROOT And what is that custom? I think he means camelCase naming syntax. It does tend to involve fewer keystrokes and results in shorter names that might more easily fit to a screen or paper, but I have to say I prefer the underscore convention, it just makes things much more readable (which is probably why built-in PHP functions and constants use it) -- Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] global array
See - I didn't even notice he used camel-case - I thought he typed the same thing that got the OP in trouble. See how difficult that custom is? That's why for any case sensitive syntax, I stick to all lower case to avoid just that kind of bug-a-boo. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global array, can't assign values from variables
Chris Edwards wrote: I'm just going to give the code and output. It should be self explanatory. The array, $criteria, is having the issue. I don't know what it's doing. I cannot seem to assign the value from the $data variable to the $criteria[index] value. You will see some attempts to debug the situation which leads me to more puzzlement. CODE: // run when cdata is found function characterDataHandler($parser, $data) { switch( $GLOBALS['currentTag'] ) { case MINSTARTDATE : echo $data;/*$GLOBALS['criteria']['minstartdate'] = $data;*/break; case MAXSTARTDATE : $GLOBALS['criteria']['maxstartdate'] = junk;/*$data;*/break; case MINSTAY : $GLOBALS['criteria']['minstay'] = $data; break; [snip] echo pre\n; print_r($criteria); echo /pre\n; OUTPUT: 9/6/2003 Array ( [maxstartdate] = junk [minstay] = [snip] $data is empty. How are you calling this function? -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] global array, can't assign values from variables SOLVED
Hi $data is not empty. It's obvious from the : OUTPUT: 9/6/2003 Anyways, it is overwriting itself because of begin and start tags. I didn't realize that. Thanks. -- Chris Edwards Web Application Developer Outer Banks Internet, Inc. 252-441-6698 [EMAIL PROTECTED] http://www.OuterBanksInternet.com - Original Message - From: John W. Holmes [EMAIL PROTECTED] To: Chris Edwards [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Friday, September 05, 2003 4:11 PM Subject: Re: [PHP] global array, can't assign values from variables Chris Edwards wrote: I'm just going to give the code and output. It should be self explanatory. The array, $criteria, is having the issue. I don't know what it's doing. I cannot seem to assign the value from the $data variable to the $criteria[index] value. You will see some attempts to debug the situation which leads me to more puzzlement. CODE: // run when cdata is found function characterDataHandler($parser, $data) { switch( $GLOBALS['currentTag'] ) { case MINSTARTDATE : echo $data;/*$GLOBALS['criteria']['minstartdate'] = $data;*/break; case MAXSTARTDATE : $GLOBALS['criteria']['maxstartdate'] = junk;/*$data;*/break; case MINSTAY : $GLOBALS['criteria']['minstay'] = $data; break; [snip] echo pre\n; print_r($criteria); echo /pre\n; OUTPUT: 9/6/2003 Array ( [maxstartdate] = junk [minstay] = [snip] $data is empty. How are you calling this function? -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- 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
Re: [PHP] global array, can't assign values from variables
* Thus wrote Chris Edwards ([EMAIL PROTECTED]): Hi I'm just going to give the code and output. It should be self explanatory. The array, $criteria, is having the issue. I don't know what it's doing. I cannot seem to assign the value from the $data variable to the $criteria[index] value. You will see some attempts to debug the situation which leads me to more puzzlement. This code can't be clearly evaluated, There are several things that can be wrong CODE: switch( $GLOBALS['currentTag'] ) { case MINSTARTDATE : echo $data;/*$GLOBALS['criteria']['minstartdate'] = $data;*/break; case MAXSTARTDATE : $GLOBALS['criteria']['maxstartdate'] = junk;/*$data;*/break; case MINSTAY : $GLOBALS['criteria']['minstay'] = $data; break; case MAXSTAY : $GLOBALS['criteria']['maxstay'] = $data; break; case MINRENT : $GLOBALS['criteria']['minrent'] = $data; break; case MAXRENT : $GLOBALS['criteria']['maxrent'] = $data; break; case RENTINC : $GLOBALS['criteria']['rentinc'] = $data; break; case MINBEDS : $GLOBALS['criteria']['minbeds'] = $data; break; case MAXBEDS : $GLOBALS['criteria']['maxbeds'] = $data; break; case PROPCOUNT : $GLOBALS['criteria']['propcount'] = $data; break; default: break; } global $currentTag may be: not assigned not all uppercase have a leading or trailing space not be one of the 'case' values $data is empty. Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php