johnmerlino Posted August 6, 2011 Share Posted August 6, 2011 Hey all, this function returns 0, rather than a string consisting of html tags: function cost_per_distance_table($distance,$divisor){ $str = ""; $str += "<table>"; $str += "<tr>"; $str += "<td>Distance</td>"; $str += "<td>Cost</td>"; $str += "</tr>"; while($distance <= 250){ $str += "<tr>"; $str += "<td>" . (string)$distance . "</td>\n"; $str += "<td>" . (string)($distance/$divisor) . "</td>\n"; $str += "</tr>"; $distance += 50; } $str += "</table>"; return $str; } echo cost_per_distance_table(50,10); Not sure why. Thanks for response. Link to comment https://forums.phpfreaks.com/topic/244015-expecting-function-to-return-an-html-table-it-returns-integer-0-instead/ Share on other sites More sharing options...
cunoodle2 Posted August 6, 2011 Share Posted August 6, 2011 as far as I know strings use ".=" to add to the end. "+=" is a math operation. Link to comment https://forums.phpfreaks.com/topic/244015-expecting-function-to-return-an-html-table-it-returns-integer-0-instead/#findComment-1253116 Share on other sites More sharing options...
johnmerlino Posted August 6, 2011 Author Share Posted August 6, 2011 as far as I know strings use ".=" to add to the end. "+=" is a math operation. Your right. Im getting programming languages mixed up Link to comment https://forums.phpfreaks.com/topic/244015-expecting-function-to-return-an-html-table-it-returns-integer-0-instead/#findComment-1253117 Share on other sites More sharing options...
zavaboy Posted August 6, 2011 Share Posted August 6, 2011 It's a common mistake if you're used to JavaScript or the like. (Even I still do it and I've been coding PHP for almost 10 years now.) Link to comment https://forums.phpfreaks.com/topic/244015-expecting-function-to-return-an-html-table-it-returns-integer-0-instead/#findComment-1253118 Share on other sites More sharing options...
phpSensei Posted August 6, 2011 Share Posted August 6, 2011 Best programming habit you can possible inherit from any language is probably indenting your code from Python. Tip of the day lol. Link to comment https://forums.phpfreaks.com/topic/244015-expecting-function-to-return-an-html-table-it-returns-integer-0-instead/#findComment-1253120 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.