$my_row[blah] or $a_row[blah] or $row[blah] Which one?
Moderator: General Moderators
-
flash
- Forum Newbie
- Posts: 1
- Joined: Tue Oct 08, 2002 10:13 am
- Location: Cambria, CA ~ Where the Pines Meet the Sea
- Contact:
$my_row[blah] or $a_row[blah] or $row[blah] Which one?
Just curious, I'm guessing one could use $a_bannana[blah]? How do you prefer to proceed? Why the underscore?
Re: $my_row[blah] or $a_row[blah] or $row[blah] Which one?
The answer in short to your last question - the underscore represents a space where a literal space is an invalid character for a variable name to contain.flash wrote:Just curious, I'm guessing one could use $a_bannana[blah]? How do you prefer to proceed? Why the underscore?
http://www.php.net/manual/en/language.variables.php
As for my preference, I tend to name all of my classes and functions using the following format: mySpecialClass or mySpecialFunction() -- Java influence I guess. I tend to use underscores in all variable names unless I am instantiating a class, then I tend to use a uniform variable string compared to the class name. e.g.
Code: Select all
<?php
$mySpecialClass = new MySpecialClass;
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Whichever one you choose make sure that you quote your array's element names so $array['element'] not $array[element], not quoting them means that PHP does a bunch of extra work looking for a constant (in this example called element) which doesn't exist and then when it doesn't find it it assumes you meant 'element' not element.
Mac
Mac
Mac, great tip.
I've wondered whats best. I thought that as we are dealing with arrays, $array[element] was best without the quotes, like C++ array[3], y'know an index rather than a string.
Time to search all my files and do some replacing, should save a load of server processing time.
PS. I use $row[blah], thats what the example said and seems to make perfect sense to me, like picking a row from the table.
I've wondered whats best. I thought that as we are dealing with arrays, $array[element] was best without the quotes, like C++ array[3], y'know an index rather than a string.
Time to search all my files and do some replacing, should save a load of server processing time.
PS. I use $row[blah], thats what the example said and seems to make perfect sense to me, like picking a row from the table.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
php-arrays are a mixtures of perl-hashes and perl-arrays (where perl-arrays are more like those you know from C/C++)
you can use what ever you want as index (I think even ressources like database-connections) as long as you could assign it to a variable as well (and of course: could use an equal-comparison).
$a = element; would cause a parse-error (as long as element is not defined as constant i.e.) but you could do $a = 'element';
Since you can assign a numeric value without quotes ($i = 3) $arr[3] = ...; is correct
you can use what ever you want as index (I think even ressources like database-connections) as long as you could assign it to a variable as well (and of course: could use an equal-comparison).
$a = element; would cause a parse-error (as long as element is not defined as constant i.e.) but you could do $a = 'element';
Since you can assign a numeric value without quotes ($i = 3) $arr[3] = ...; is correct