Difference between “as $key => $value” and “as $value” in PHP foreach

Well, the $key => $value in the foreach loop refers to the key-value pairs in associative arrays, where the key serves as the index to determine the value instead of a number like 0,1,2,… In PHP, associative arrays look like this: In the PHP code: $featured is the associative array being looped through, and as … Read more

List of All Locales and Their Short Codes?

The importance of locales is that your environment/os can provide formatting functionality for all installed locales even if you don’t know about them when you write your application. My Windows 7 system has 211 locales installed (listed below), so you wouldn’t likely write any custom code or translation specific to this many locales. Edit: The … Read more

How do I make a redirect in PHP?

Summary of existing answers plus my own two cents: 1. Basic answer You can use the header() function to send a new HTTP header, but this must be sent to the browser before any HTML or text (so before the <!DOCTYPE …> declaration, for example). 2. Important details die() or exit() Why you should use die() or exit(): The Daily WTF Absolute or relative URL … Read more

How to use mysqli_query() in PHP?

I have to admit, mysqli_query() manual entry doesn’t contain a clean example on how to fetch multiple rows. May be it’s because the routine is so routine, known to PHP folks for decades: In case you want to print the column titles, you have to select your data into a nested array first and then use keys … Read more

How do I make a redirect in PHP?

Use the header() function to send an HTTP Location header: Contrary to what some think, die() has nothing to do with redirection. Use it only if you want to redirect instead of normal execution. File example.php: Result of three executions: Resuming — obligatory die()/exit() is some urban legend that has nothing to do with actual PHP. It has nothing to do with client “respecting” the Location: header. Sending a header does not … Read more

navigate back with PHP form submission

When you post forms with php, or any other data, you may come back to the page and find a message in the browser like “Document Expired” or “Confirm Form Resubmission With Chrome”. These messages are a safety precaution the browser uses with sensitive data such as post variables. The browser will not automatically give … Read more

Google Calendar API event update always return 404 “not found” error

$service->events->get expects the calendar id and event id as parameters It is important to double-check that both parameters are correct If ‘mygooglecalendarid’ is not your primary calendar, then you are trying to get the event from one calendar and update it into a different one – this will give you a 404 error (bad request). If the eventid is not … Read more