r_honey Posted June 25, 2007 Share Posted June 25, 2007 There are two things I am trying to accompolish with PHP types & arrays. Hope somebody here can help me: 1) You can use $a = integer; in PHP. That helps you to recapture the purpose of the variable when you or others visit the code later. I am trying to initialize the above variable, i.e. something like $a = integer =5 ; or $a = integer(5); All these give parse errors. Is it possible to accompolish what I am trying??? 2) You can return an array for indexing with both associative & otherwise, with mysql functions. I need to provide a similar functionality in my library, where users can enter elements in an array using keys, but retrieve it later using numeric indexes in the order in which they were entered. So, is this feasible??? Quote Link to comment Share on other sites More sharing options...
Lumio Posted June 25, 2007 Share Posted June 25, 2007 1) <?php $a = 5 //integer $b = 5.01 //float if (is_numeric($a)) echo '$a is numeric<br />'; if (is_numeric($b)) echo '$b is numeric<br />'; if (is_int($a)) echo '$a is an integer<br />'; if (is_int($a)) echo '$b is an integer'; ?> 2) You mean something, like an array? Quote Link to comment Share on other sites More sharing options...
r_honey Posted June 25, 2007 Author Share Posted June 25, 2007 I believe you did not get my point. Ok then, tell me if $a = integer; is valid or not in PHP??? And ues, I mean like an array... Quote Link to comment Share on other sites More sharing options...
redarrow Posted June 25, 2007 Share Posted June 25, 2007 This is the only way ok post ansaw has already been posted <?php $a = 5 //integer $b = 5.01 //float if (is_numeric($a)) echo '$a is numeric<br />'; if (is_numeric($b)) echo '$b is numeric<br />'; if (is_int($a)) echo '$a is an integer<br />'; if (is_int($a)) echo '$b is an integer'; ?> please tell us what ur tying to do ok. Quote Link to comment Share on other sites More sharing options...
trq Posted June 25, 2007 Share Posted June 25, 2007 You can use typecasting in php. eg; <?php $a = (int) 5; ?> Quote Link to comment Share on other sites More sharing options...
r_honey Posted June 25, 2007 Author Share Posted June 25, 2007 Looks like type casting or type checking is the only solution. Thanx guys... Quote Link to comment Share on other sites More sharing options...
trq Posted June 25, 2007 Share Posted June 25, 2007 PHP is a dynamically typed language. Its a feature. If you really need this functionality, your probably using the wrong language. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.