FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » integer and string what's the difference ?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: integer and string what's the difference ? [message #175861 is a reply to message #175860] Tue, 01 November 2011 15:23 Go to previous messageGo to previous message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma:
Senior Member
On Tue, 1 Nov 2011 06:19:01 -0700 (PDT), gaoqiang wrote:

> 1 <?php
> 2 require_once("config.php");
> 3 $now=time();
> 4 $value="abcd";
> 5 $key="1234";
> 6
> 7 $mem_server="localhost";
> 8 $mem_port=11211;
> 9 $memc=new Memcached;
> 10 $memc->addServer($mem_server,$mem_port);
> 11 $memc->set($key,$value);
> 12 $keys=array();
> 13 array_push($keys, 1234);
> 14 $rsts=$memc->getMulti($keys);
> 15 var_dump($rsts);
> 16 ?>
>
> line 13: when using array_push($keys,"1234"),
> it works fine. but not with 1234.
>
> when using $memc->get,not getMulti, 1234 and
> "1234" are the same.
>
> I think this is a bug. any idea ?

An integer is any numeric value.
Where some will argue that an integer is any whole number like 0 or 1.
But is "1" the same as 1? No it is not.

I once came across a web page that asked this simple question:
When does '1'+'1'='11'?
Notice the quotes.
in computer math 1+1=2.
But '1'+'1'='11'


In your code above, check line 13.
In line 5 you defined $key="1234".
In line 13, you are treating this value as an integer, not a string as you
defined it.
The quotes define the value as a string.
Try using the quotes around 1234 and see what happens.

In BASIC, a statement like a$="hello"+world would generate an error.
So to be correct it would have to be like this:
a$="hello"+str$(world)
str$() converts an integer to a string.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: missing variable
Next Topic: Stats comp.lang.php (last 7 days)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Oct 06 04:23:02 GMT 2024

Total time taken to generate the page: 0.05573 seconds