Jump to content

heffe6

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

heffe6's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for your help everyone. My problem was I was calling this from within a class, (I failed to mention that) and I was having trouble accessing my custom sorting function. Another look through the manual, and I figured I had to do this: uasort($arr, array("className", "functionName"));
  2. Thanks for your help, this code seems to work: function sort($a, $b) { if ($a['list'] == $b['list']) { return 0; } return ($a['list'] < $b['list']) ? -1 : 1; } Then i call uasort($d, 'sort'); When I output my array, the sort works. But I get the following warnings: Warning (2): sort() expects parameter 2 to be long, array given [APP\models\timesheet.php, line 103] Warning (2): uasort() [function.uasort]: Array was modified by the user comparison function [APP\models\timesheet.php, line 103] Any ideas?
  3. Hello everyone, Im trying to sort this array: Array ( [35] => Array ( [first_name] => Dave [last_name] => Park [cost] => 35 [amt] => 3 ) [46] => Array ( [first_name] => Steven [last_name] => Lewis [cost] => 60 [amt] => 6 ) ... etc I'd like to sort the first level array by the value in [last_name], then by the value [first_name], and maintain all keys. Can anyone help?
  4. So exceptions are primarily used for system errors.. Makes sense. thank you
  5. Yes, thank you, I have done that in the past, but just thought using exceptions might offer more functionality.
  6. Hello all, I'm new to OOP, I'm having some trouble with exceptions. I've got the hang of throwing and catching them, and even creating my own exception classes, but I'd like to be able to handle the exceptions in a different part of the script then where they occur. For example, at the top of my script, I validate fields and run my sql inserts and what not. If any of those throw exceptions I want to be able to print an error message in my error message div which is further down in the HTML. I'm not able to keep everything in a try block, because regardless of an exception, I still want to print out a lot of the HTML. Here's a representation of what I'm trying to do. <?php - validate form, if it fails, throw exception - run sql, if it fails, throw exception ?> <html> - some data I want to appear regardless - - if there are no exceptions, php data will be echoed here <div id="error_message"> - catch Excpetion - and display relevant error message </div> </html> I have a feeling I'm thinking about this incorrectly? If this is not what exceptions are meant for, can anyone suggest a better way to do this? Thanks, -Jeff
  7. Makes sense - thanks!
  8. Hello everyone, I'm new here, but this seems like a great forum. I have a quick question that I haven't able to find a definitive answer to. I'm trying to teach myself php, and I want to be able to write with best practices in mind. Is it generally a better idea to create HTML with your php code like this?: <?php for($x=0;$x<5;$x++){ echo "<td>Number:</td>"; echo "<td>" . $x . "</td>"; } ?> Or is it better to write the php around the html like this?: <?php for($x=0;$x<5;$x++){ ?> <td>Number:</td> <td><?php echo $x ?></td> <?php } ?> Thanks!
×
×
  • 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.