Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,971 questions

51,913 answers

573 users

How to set variable type in PHP

4 Answers

0 votes
$s = "100 A Grade"; 
 
echo $s . " : " . gettype($s) . "\n";
settype($s, "integer");
echo $s . " : " . gettype($s) . "\n";




/*
run:

100 A Grade : string
100 : integer

*/

 



answered Jul 17, 2016 by avibootz
edited Oct 19, 2023 by avibootz
0 votes
$s = true; 
 
echo $s . " : " . gettype($s) . "\n";
settype($s, "integer");
echo $s . " : " . gettype($s) . "\n";




/*
run:

1 : boolean
1 : integer

*/

 



answered Jul 17, 2016 by avibootz
edited Oct 19, 2023 by avibootz
0 votes
$s = "php";
 
echo $s . " : " . gettype($s) . "\n";
settype($s, "integer");
echo $s . " : " . gettype($s) . "\n";




/*
run:

php : string
0 : integer

*/

 



answered Jul 17, 2016 by avibootz
edited Oct 19, 2023 by avibootz
0 votes
$a = 14;
 
echo $a . " : " . gettype($a) . "\n";
settype($a, "string");
echo $a . " " . gettype($a) . "\n\n";
 
 
$a = "489";
 
echo $a . " : " . gettype($a) . "\n";
settype($a, "integer");
echo $a . " : " . gettype($a) . "\n";
 
 
 
 
 
/*
run:
 
14 : integer
14 string

489 : string
489 : integer

*/

 



answered Oct 19, 2023 by avibootz

Related questions

1 answer 139 views
1 answer 121 views
121 views asked Aug 24, 2020 by avibootz
1 answer 203 views
2 answers 243 views
1 answer 200 views
9 answers 683 views
...