Jump to content

yet another question from me!


BigCanadian

Recommended Posts

hey guys, Im afraid I will be posting a lot of questions as I slowly work my way through these tutorials... simple question though.

it says that it can convert this string into an integer what I dont understand is I thoguht integers could only be numbers... so how can he change the $mystring into an integer?

<?php
  $mystring = "wombat";
  $myinteger = (integer)$mystring
?>


heres the link

[url=http://hudzilla.org/phpwiki/index.php?title=Forcing_a_type_with_type_casting]http://hudzilla.org/phpwiki/index.php?title=Forcing_a_type_with_type_casting[/url]
Link to comment
https://forums.phpfreaks.com/topic/28060-yet-another-question-from-me/
Share on other sites

From what I understand:

It will keep it an integer (number) until there is a letter. After the letter, it will not echo anything. If there are no numbers, it will show a 0

[code]<?php
  $mystring = "1c2234234a3";
  $myinteger = (integer)$mystring;
echo $myinteger;
?>[/code]
Will output: 1

[code]<?php
  $mystring = "12234234a3";
  $myinteger = (integer)$mystring;
echo $myinteger;
?>[/code]
Will output: 12234234

[code]<?php
  $mystring = "abc";
  $myinteger = (integer)$mystring;
echo $myinteger;
?>[/code]
Will output: 0

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.