An alternate approach would be to use array_pad on the array to ensure its length (if all the defaults you need to add are the same).If you want use the undefined behaviour as you might expect it e.g.if you want: $b = ['a','b']; list($a, $b) = $b;to result in $a=='a' and $b=='b', then you can just cast $b to an array (even although it already is) to create a copy. $b = ['a','b']; list($a, $b) = (array)$b;and get the expected results.
If you aren't careful, you can get stuck in a while loop comparing days of the week with something like:$now will return the same (the server's current) Unix time stamp regardless which timezone your user is in.
This is much more obvious on the "zero-padded" results, but it's worth repeating.
Thanks to tcasparr at gmail dot com for the great idea (at least for me) ;)I changed the code a little to replicate the functionality of date_parse_from_format, once I don't have PHP 5.3.0 yet. Hope you don't mind changing your code tcasparr at gmail dot com./******************************************************* * Simple function to take in a date format and return array of associated * formats for each date element * * @return array * @param string $str Format * * Example: Y/m/d g:i:s becomes * Array * ( * [year] =/** * Convert a strftime format to a date format * * Unsupported strftime formats : %U, %W, %C, %g, %r, %R, %T, %X, %c, %D, %F, %x * Unsupported date formats : S, n, t, L, B, G, u, e, I, P, Z, c, r * * @param string $strftime Format a strftime format * @return string */ If you are having an issue getting u to work so is everyone else.
first you need to convert the object to numeric indexed array.ex: list($a, $b, $d) = (array) $abc; // $abc is an object; this will not assign.list($a, $b, $c) = array_values((array) $abc); // This will work.
Second, when you’re using the list() function, you must acknowledge each array element.
This is very good for SEO especially search engines like Google . To get the actual Unix time stamp based on a time zone, replace format('U') as in the following example;in the "datetime" attribute you should put a machine-readable value which represent time , the best value is a full time/date with ISO 8601 ( date('c') ) ,,, the attr will be hidden from usersand it doesn't really matter what you put as a shown value to the user,, any date/time format is okay !What that obscure statement means is that if you unset an element, list will not simply jump to the next element and assign that to the variable but will treat the missing element as a null or empty variable: $test = array("a","b","c","d"); unset($test); list($a,$b,$c)=$test; print "$a='$a' $b='$b' $c='$c' if we assign array's each value individual key('numeric only'), and use the array indices in list(),, then it output the reverse order of array keys-- BUT THE HIGHER KEY VALUE ("2" in this e.g below) WILL GET THE FIRST PLACE IN THE ARRAY IN RETURN, MEANS IT PUSHES THE VALUE WITH HIGHER KEY IN PLACE OF FIRST KEY VALUE, so it also gives higher key value the first priority while reversing the order of the keys and replacing the lower key value with the higher key value.$value = array( 0 = UNDOCUMENTED BEHAVIOR: list($a,$b,$c) = null;in fact works like: $a = null; $b = null; $c = null;...So correspondingly: list($rows) = null; Will increment count($rows), just as if you had executed $rows = null; Watch out for this (for example) when retrieving entire tables from a database, e.g.while (list($rows) = $mysqlresult- 'c' ); PHP Notice: Undefined offset: 2 in Command line code on line 1 PHP Notice: Undefined offset: 1 in Command line code on line 1 PHP Notice: Undefined offset: 0 in Command line code on line 1 Note: list cannot assign array cast of object to variables straight away.