It should already be in that order. PHP arrays are sorted so the elements will be in the order in which you inserted them You also need to call empty() on $value not $key $key should always be non-empty. You also don't need isset() as well as empty() Apart from that your code works fine and produces the desired output I would also be wary of using empty() because it will return true for a string '0'.
This could be a valid parameter value which would be ignored. You could instead check that strlen($value) > 0.
It should already be in that order. PHP arrays are sorted so the elements will be in the order in which you inserted them. You also need to call empty() on $value not $key; $key should always be non-empty.
You also don't need isset() as well as empty(). Apart from that your code works fine and produces the desired output. I would also be wary of using empty() because it will return true for a string '0'.
This could be a valid parameter value which would be ignored. You could instead check that strlen($value) > 0.
Thanks very much for your answer. I had originally supposed that would be the case. However, using the above code, my html output is: Which suggests that my isset() /!empty() combination is incorrect, and also that, for some reason, my order is also incorrect.
However, when I print_r() the array, it shows up in the correct order as it should. How can I continue to troubleshoot this? Much thanks for a quick response!
– Steve K Jul 14 '09 at 11:04 I apologize, for some reason, the input html did not post correctly, and I cannot edit or delete that comment, so I'll try to post it in the order it actually appears: – Steve K Jul 14 '09 at 11:06 Much thanks for the heads up about empty on value rather then on key. For some reason I had the silly thought that doing a check for an empty key would tell me if its value was empty... Oy. Thanks again for your help, it's much-appreciated.
– Steve K Jul 14 '09 at 11:29.
Running the following code through PHP's interactive commandline just affirms Tom Haigh's statement It should already be in that order. PHP arrays are sorted so the elements will be in the order in which you inserted them. 'text', 'class'=>'input', 'name'=>'username', 'id'=>'username', 'value'=>'', 'size'=>'30', 'rows'=>'', 'cols'=>'' ); print_r($a); /* Array ( type => text class => input name => username id => username value => size => 30 rows => cols => ) */ foreach ($a as $k => $v) { echo $k .' => ' .
$v . "\n"; } /* type => text class => input name => username id => username value => size => 30 rows => cols => */ You're sure that this is exactly the code you're using and there is nothing happening to $input_array between creation and looping? EDIT: Just a simple and perhaps stupid question: Where do you check how the resulting string in $input looks like?
If you do so in e.g. FireBug's HTML navigator the attributes' order won't match the real order in the HTML source as FireBug displays the DOM tree generated from the source (and potential Javascript manipulation) which means that it can reorder the attributes at will...
This firebug issue is precisely the problem I was having. Only after checking the source did I realize that what Mr. Haigh said was in fact true. Much thanks!
– Steve K Jul 14 '09 at 12:43.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.