Jpoel Posted December 14, 2008 Share Posted December 14, 2008 Its simple enough, but when i run the php script it returns null ??? Anyone got any idea whats up? $Month = "Aug"; $Months = array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); $MonthNumber = array_search($Month,$Months); die($MonthNumber); Thanks :/ Quote Link to comment https://forums.phpfreaks.com/topic/136938-solved-why-wont-this-work/ Share on other sites More sharing options...
wildteen88 Posted December 14, 2008 Share Posted December 14, 2008 Code runs fine when you use echo and not die. Quote Link to comment https://forums.phpfreaks.com/topic/136938-solved-why-wont-this-work/#findComment-715215 Share on other sites More sharing options...
Jpoel Posted December 14, 2008 Author Share Posted December 14, 2008 Code runs fine when you use echo and not die. Cheers! Strange why that wouldnt work I wanted the code to stop executing there, so i changed die($MonthNumber); to echo $MonthNumber; die(); And it worked fine Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/136938-solved-why-wont-this-work/#findComment-715224 Share on other sites More sharing options...
PFMaBiSmAd Posted December 14, 2008 Share Posted December 14, 2008 It's because die() expects a string in order to print it. An integer cause that value to be returned to the calling program (assuming php was called by another program that expects a return value.) If status is a string, this function prints the status just before exiting. If status is an integer, that value will also be used as the exit status. Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully. Note: PHP >= 4.2.0 does NOT print the status if it is an integer. This works - die("$MonthNumber"); Quote Link to comment https://forums.phpfreaks.com/topic/136938-solved-why-wont-this-work/#findComment-715227 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.