[PHP] professional code quick tip

2005-09-20 Thread adriano ghezzi
hy guys this night I'm quite tired 

I need a little tip

 ok var n could be from 0 to 12

var f must be set 
f=1 if0n=4
f=2 if   5n=7
f=3 if  8n=12
f=4 if n12

due to my fatigue I coded four if-if else statement,

in other languages it is possible use conditional epression in switch case
like 
switch $n

case (0n=4):


but no in php

any suggestion for more professional coding then 4 if/else statement

tia

a.g.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] professional code quick tip

2005-09-20 Thread Robert Cummings
On Tue, 2005-09-20 at 19:20, adriano ghezzi wrote:
 hy guys this night I'm quite tired 
 
 I need a little tip
 
  ok var n could be from 0 to 12
 
 var f must be set 
 f=1 if0n=4
 f=2 if   5n=7
 f=3 if  8n=12
 f=4 if n12
 
 due to my fatigue I coded four if-if else statement,
 
 in other languages it is possible use conditional epression in switch case
 like 
 switch $n
 
 case (0n=4):
 
 
 but no in php
 
 any suggestion for more professional coding then 4 if/else statement

For such a small set I'd say that's as good as it gets. However if there
were 100 intervals you could try the following:

function f( $n )
{
$map = array
(
// min,   max,f
array(   0, 4,1 ),
array(   5, 7,2 ),
array(   8,12,3 ),
array(  17,  null,4 ),
);

foreach( $map as $criteria )
{
if( $criteria[0] === null || $n  $criteria[0]

$criteria[1] === null || $n = $criteria[1] )
{
return $criteria[2];
}
}

return null;
}

I think your code is flawed by the way, the lower endpoints are only
compared for greater than value and not equal to value meaning $n with
value 4 would not match any f value.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] professional code quick tip

2005-09-20 Thread Thorsten Suckow-Homberg
in other languages it is possible use conditional epression in switch 
case

like
switch $n

case (0n=4):


but no in php


You could use the following statement:

?php
switch (true) {
case (0  $n = 4):
$f = 1;
break;
case (5  $n = 7):
$f = 2;
break;
case (8  $n = 12):
$f = 3;
break;
default:
$f = 4;
break;
}
?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] professional code quick tip

2005-09-20 Thread Robert Cummings
On Tue, 2005-09-20 at 19:47, Thorsten Suckow-Homberg wrote:
 You could use the following statement:
 
 ?php
 switch (true) {
 case (0  $n = 4):
 $f = 1;
 break;
 case (5  $n = 7):
 $f = 2;
 break;
 case (8  $n = 12):
 $f = 3;
 break;
 default:
 $f = 4;
 break;
 }

I'm certain that is illegal.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] professional code quick tip

2005-09-20 Thread Thorsten Suckow-Homberg

I'm certain that is illegal.


Wanna bet? :)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] professional code quick tip

2005-09-20 Thread Jasper Bryant-Greene

Robert Cummings wrote:

On Tue, 2005-09-20 at 19:47, Thorsten Suckow-Homberg wrote:


You could use the following statement:

?php
switch (true) {
case (0  $n = 4):
$f = 1;
break;
case (5  $n = 7):
$f = 2;
break;
case (8  $n = 12):
$f = 3;
break;
default:
$f = 4;
break;
}



I'm certain that is illegal.


I don't think so, although I'm not able to test it right at this second. 
 PHP compares the value within the switch statement to the value at 
each case. Only the case which is true will match true inside the switch 
statement, so it should actually work as intended.


--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] professional code quick tip

2005-09-20 Thread Robert Cummings
On Tue, 2005-09-20 at 19:55, Thorsten Suckow-Homberg wrote:
  I'm certain that is illegal.
 
 Wanna bet? :)

$100... cuz I'm sure you didn't mean to compound those conditionals such
that PHP doesn't understand them ;)

snaffu:~ php foo.php
Content-type: text/html
X-Powered-By: PHP/4.4.0

br /
bParse error/b:  parse error, unexpected T_IS_SMALLER_OR_EQUAL in
b/home/suds/foo.php/b on line b4/bbr /


-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] professional code quick tip

2005-09-20 Thread Jasper Bryant-Greene

Robert Cummings wrote:

On Tue, 2005-09-20 at 19:55, Thorsten Suckow-Homberg wrote:


I'm certain that is illegal.


Wanna bet? :)



$100... cuz I'm sure you didn't mean to compound those conditionals such
that PHP doesn't understand them ;)


Fair enough, but I believe it was the use of the switch statement for 
that purpose that he was pointing out; with a few modifications it works 
fine:


?php
switch( true ) {
case ( 0  $n  $n = 4 ):
$f = 1;
break;
case ( 5  $n  $n = 7 ):
$f = 2;
break;
case ( 8  $n  $n = 12 ):
$f = 3;
break;
default:
$f = 4;
break;
}
?

--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] professional code quick tip

2005-09-20 Thread Thorsten Suckow-Homberg

$100... cuz I'm sure you didn't mean to compound those conditionals such
that PHP doesn't understand them ;)


nargh... yes you're right... send me your account information along with 
your paypal login. I'll send you the money asap ;) 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] professional code quick tip ---last---

2005-09-20 Thread adriano ghezzi
thx to all
-- final release  good nigh!

$f=0;

if ( $ar[0]0 and $ar[0]=12)
$f=1;


elseif ( $ar[0]12 and $ar[0]=14)
$f=2;

elseif ( $ar[0]14 and $ar[0]=18)
$f=3;

if ( $ar[0]18)
$f=4;







2005/9/21, Robert Cummings [EMAIL PROTECTED]:
 On Tue, 2005-09-20 at 19:20, adriano ghezzi wrote:
  hy guys this night I'm quite tired
 
  I need a little tip
 
   ok var n could be from 0 to 12
 
  var f must be set
  f=1 if0n=4
  f=2 if   5n=7
  f=3 if  8n=12
  f=4 if n12
 
  due to my fatigue I coded four if-if else statement,
 
  in other languages it is possible use conditional epression in switch case
  like
  switch $n
 
  case (0n=4):
  
 
  but no in php
 
  any suggestion for more professional coding then 4 if/else statement
 
 For such a small set I'd say that's as good as it gets. However if there
 were 100 intervals you could try the following:
 
 function f( $n )
 {
$map = array
(
// min,   max,f
array(   0, 4,1 ),
array(   5, 7,2 ),
array(   8,12,3 ),
array(  17,  null,4 ),
);
 
foreach( $map as $criteria )
{
if( $criteria[0] === null || $n  $criteria[0]

$criteria[1] === null || $n = $criteria[1] )
{
return $criteria[2];
}
}
 
return null;
 }
 
 I think your code is flawed by the way, the lower endpoints are only
 compared for greater than value and not equal to value meaning $n with
 value 4 would not match any f value.
 
 Cheers,
 Rob.
 --
 ..
 | InterJinn Application Framework - http://www.interjinn.com |
 ::
 | An application and templating framework for PHP. Boasting  |
 | a powerful, scalable system for accessing system services  |
 | such as forms, properties, sessions, and caches. InterJinn |
 | also provides an extremely flexible architecture for   |
 | creating re-usable components quickly and easily.  |
 `'
 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php