Jump to content

Type Juggling in PHP


r_honey

Recommended Posts

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???

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.