joyser Posted February 23, 2009 Share Posted February 23, 2009 ok, i have two varibles.. this is my statment: $hours = $hours-$time_change; $hours = 15 and $timechange = 8. However when i echo the result, i get this: 15-8 why is this? is it something to do with variable type? if so, how do i fix it? Link to comment https://forums.phpfreaks.com/topic/146434-noobie-question-about-variable-types/ Share on other sites More sharing options...
npsari Posted February 23, 2009 Share Posted February 23, 2009 I think the problem may be with the Quotation marks Or the fact that you chose the variable hours 2 times just change it to... $result = $hours - $time_change ; echo "$result"; Link to comment https://forums.phpfreaks.com/topic/146434-noobie-question-about-variable-types/#findComment-768801 Share on other sites More sharing options...
joyser Posted February 23, 2009 Author Share Posted February 23, 2009 nope, still doesn't work Link to comment https://forums.phpfreaks.com/topic/146434-noobie-question-about-variable-types/#findComment-768806 Share on other sites More sharing options...
phpdragon Posted February 23, 2009 Share Posted February 23, 2009 I cannot repeat your issue, here is the code I am using and this works fine <?php $hours=15; $time_change=8; $hours=$hours-$time_change; echo $hours; ?> is yours similar? Link to comment https://forums.phpfreaks.com/topic/146434-noobie-question-about-variable-types/#findComment-768808 Share on other sites More sharing options...
joyser Posted February 23, 2009 Author Share Posted February 23, 2009 thanks for replying guys my code is like this: $hours = substr($timestamp, 9, 2); ($timestamp is a big long string with date and time etc.) $hours = $hours-$time_change; Link to comment https://forums.phpfreaks.com/topic/146434-noobie-question-about-variable-types/#findComment-768814 Share on other sites More sharing options...
npsari Posted February 23, 2009 Share Posted February 23, 2009 hmm, so, are you sure if you echo $hours and $time_change they will be simple numbers Because if they are simple numbers, then, i think there should be no problem Perhaps you need to show the whole script from start to end for better help Link to comment https://forums.phpfreaks.com/topic/146434-noobie-question-about-variable-types/#findComment-768817 Share on other sites More sharing options...
phpdragon Posted February 23, 2009 Share Posted February 23, 2009 echo your 2 variables to the page with no calculations and see what it lists Link to comment https://forums.phpfreaks.com/topic/146434-noobie-question-about-variable-types/#findComment-768849 Share on other sites More sharing options...
linkednet Posted February 23, 2009 Share Posted February 23, 2009 I read the PHP Manual for substr, this is what I understand. Straight from PHP.net. http://us3.php.net/substr string substr ( string $string , int $start [, int $length ] ) Returns the portion of string specified by the start and length parameters. $rest = substr("abcdef", -3, 1); // returns "d" It basically starts between c and d and counts 1. $timestamp = 2/22/09 $hours = substr($timestamp, 3, 2); $hours = $hours - $time_change; echo $hours; It will print: 2/ Link to comment https://forums.phpfreaks.com/topic/146434-noobie-question-about-variable-types/#findComment-768892 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.