> -----Original Message-----
> From: Esteban Fernandez [mailto:[EMAIL PROTECTED]
> Sent: 04 June 2003 16:09
>
> Also works... :)
> 
> <?php
> $array = get_loaded_extensions();
> for ($i=0;$i<=count($array);$i++) {
>     if ("gd" == $array[$i])  $installed = true;
>     else $installed = false;
> }

This will only work if the "gd" entry is last in the array, as you don't exit the loop 
after setting $installed to true.  Plus a foreach loop would be better; and 
initialising before the loop would be more efficient, too:

   $installed = false;
   foreach ($array as $extn):
      if ("gd" == $extn):
         $installed = true;
         break;
      endif;
   endforeach;

But, even better, why not just use in_array():

   $installed = in_array("gd", $array);

> if ($installed = true) echo "yeah... GD installed";

Arrgh!  Firstly, this will assign true to $installed, then decide that's true (!) and 
echo "yeah" -- you should have used == not =.  Secondly, there is *never* any need to 
use the comparison "== true" -- again that's just forcing PHP to do unnecessary work 
(since the thing you're comparing to true must evaluate to true for the comparison to 
succeed and return true, you can omit the comparison and just use the raw value in the 
test).

> else echo "shit.. GD not installed.";
> ?>

   if ($installed) echo "yeah";
   else echo "nope";

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

Reply via email to