DeanWhitehouse Posted January 2, 2009 Share Posted January 2, 2009 Is it possible to check an array for a certain key rather than just the value. E.g. $array = array("test",50 => "tester"); if(in_array_key(50,$array)) echo "In array key"; That will return true because the key is named 50. Any ideas? Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted January 2, 2009 Share Posted January 2, 2009 array_key_exists() Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted January 2, 2009 Author Share Posted January 2, 2009 o` Thanks had the manual open but was looking near the bottom of the list of functions :s Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted January 2, 2009 Author Share Posted January 2, 2009 Not sure where to post this, but it might come in handy for some people. If you use a custom 404 page, etc. Then here is an array containing the error message and error description. <?php if(isset($_GET['error'])) { $error = $_GET['error']; $error_ids = array( 400 => "Bad Request", 401 => "Authorization Required", 402 => "Unknown Error", 403 => "Forbidden", 404 => "Not Found", 405 => "Method Not Allowed", 406 => "Not Acceptable", 407 => "Proxy Authentication Required", 408 => "Request Timed Out", 409 => "Conflicting Request", 410 => "Gone", 411 => "Content Length Required", 412 => "Precondition Failed", 413 => "Request Entity Too Long", 414 => "Request URI Too Long", 415 => "Unsupported Media Type", 500 => "Internal Server Error", 501 => "Unknown Error", 502 => "Bad Gateway", 503 => "Service Unavailable", 504 => "Gateway Timeout", 505 => "HTTP Version Not Supported" ); $error_det = array( 400 => "a syntax error in the request.", 401 => "you not having permission to access this data.", 402 => "unknown reasons.", 403 => "you not having permission to access this data or the server being unable to server the requested data.", 404 => "this document either no longer existing, or never existing on the server, or being moved or renamed.", 405 => "the method you are using to access the document not being allowed.", 406 => "this browser does not accept this document format", 407 => "this browser not beening authenticated on the required proxy server required to access the data", 408 => "the server closing the socket due to communications between you and server taking too long.", 409 => "too many requests for the same file at one time, or there is a conflict with an established software rule or, a DNS issue.", 410 => "the file not being found, but the file may be being updated and therefore should return.", 411 => "trying to send a document to the server but the server did not recieve a Content-Length specification in the header.", 412 => "a precondition setting required by you or server has not been met.", 413 => "the process being too large to process.", 414 => "the URL requested being too long.", 415 => "the server not supporting the type of media you are requesting.", 500 => "the server encountered a problem, most likely caused by a script.", 501 => "unknown reasons.", 502 => "the document being requested resides on a 3rd party server and our server received an error from the 3rd party server.", 503 => "the server being overloaded or down for maintenance.", 504 => "connectivity issues.", 505 => "our server not supporting the HTTP version used by this browser." ); if(array_key_exists($type,$error_ids)) echo $error_ids[$error]." - ".$error_det[$error]; } ?> Quote Link to comment 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.