Jump to content

[SOLVED] Why wont this work?


Jpoel

Recommended Posts

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 :/

Link to comment
Share on other sites

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 :)

 

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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