[thelist] Efficient PHP?
Ralph Guzman
ralph213 at sbcglobal.net
Tue Mar 30 03:56:56 CST 2004
The code looks fine, the only thing I would suggest is that instead of
repeatedly calling count on every loop iteration:
for ($i = 0; $i < count($arr_sbar_content[$cur_section]["pages"]); $i++){
// rest of code
}
call it once then assign it to a temporary variable which you can then use
in your for loop:
$arraysize = count($arr_sbar_content[$cur_section]["pages"]);
for ($i = 0; $i < $arraysize; $i++){
// rest of code
}
For more tips on writing efficient PHP, read this article:
Writing Efficient PHP
http://www-106.ibm.com/developerworks/edu/wa-dw-waeffphp-i.html
and also take a look at these PHP Benchmark Tests:
http://www.blueshoes.org/en/developer/php_bench/
If you haven't already, you should also subscribe to the PHP general mailing
list.
http://us4.php.net/mailing-lists.php
Happy coding!
Ralph Guzman
-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org] On Behalf Of
live4bacon at optonline.net
Sent: Monday, March 29, 2004 6:17 PM
To: thelist at lists.evolt.org
Subject: [thelist] Efficient PHP?
Another one for the PHP experts out there:
I am just discovering the wonderful world of PHP and I am curious if you all
could spare a moment to tell me what you think of the efficiency of the
following SIMPLE code (this would exist on all 60+ and growing pages of our
site) that generates the sites sidebar navigational links, which are
specific to each section, and shows the current page in bold text of a
different color.
Nothing groundbreaking here.
If you think this may be of some use to you or you would like to examine the
full code I will gladly pass it along.
Thank you,
JP
Basically I have an array holding:
1 an array of Page titles (for display in the sidebar of said section)
2 an array holding the file name for said pages
3 variable to hold the section graphic file
4 variable to hold the root relative path to the section directory
5 (OPTIONAL array to hold sub-section pages
6 (OPTIONAL array to hold sub-section page filenames)
function show_sidebar($cur_section, $cur_page = "none")
DEFINE ARRAY OF SECTIONS AND SUBSEQUENT ITEMS
DISPLAY SIDEBAR:
echo '<a href="'.$secRoot.'"><img
src="/common/images/page_elements/'.$graphic.'"></a><br>';
if($arr_sbar_content[$cur_section]["pages"]){
echo '<div class="sbar_pad"><span class="sbar_nav">';
for ($i = 0; $i <
count($arr_sbar_content[$cur_section]["pages"]); $i++){
if($arr_sbar_content[$cur_section]["pages"][$i] ==
$cur_page){
echo '<span class="current_page"><a
href="'.$secRoot.$arr_sbar_content[$cur_section]["href"][$i].'">'.$arr_sbar_
content[$cur_section]["pages"][$i].'</a><br></span>';
}
else{
echo '<a
href="'.$secRoot.$arr_sbar_content[$cur_section]["href"][$i].'">'.$arr_sbar_
content[$cur_section]["pages"][$i].'</a><br>';
}
}
echo '</span>';
ANOTHER IF STATEMENT FOR SUB-PAGES IF THEY EXIST goes here
--
* * Please support the community that supports you. * *
http://evolt.org/help_support_evolt/
For unsubscribe and other options, including the Tip Harvester
and archives of thelist go to: http://lists.evolt.org
Workers of the Web, evolt !
More information about the thelist
mailing list