Jump to content

mister5317

Members
  • Posts

    19
  • Joined

  • Last visited

    Never

Posts posted by mister5317

  1. I found it a fun learning experience to make something as simple as "HELLO WORLD!" into a difficult process.

     

    I obfuscated my PHP below to just echo "HELLO WORLD!". Anyone else have a better example to echo "HELLO WORLD!"?

     

    <?php
    // Output = HELLO WORLD!
    function __e($_){echo$_;
    }function __($_){__e(chr
    ($_));}function _a(){$__
    =func_get_args();foreach
    ($__ as$k=>$v)$a[$k]=$v;
    return$a;}foreach(_a(7,4
    ,+11,11,14,-33,22,14,17,
    11,3,-32)as$k=>$v){__(65
    +$v);}
    

     

    Give it a shot, it more difficult to think of creative ways to make something out of the box like this. :)

  2. I have timestamps in a database that are from the creation time of the records. These timestamps are something like 2009-06-29 08:54:32.

     

    In this case, I would like to round this timestamp to the nearest 15 minute increment (00:00, 00:15, 00:30, or 00:45) so the end result for 2009-06-29 08:54:32 would be 2009-06-29 09:00:00.

     

    If the time stamp was 2009-06-29 09:07:17, then the end result would still be 2009-06-29 09:00:00.

     

    Another option, if possible, would be to always round up. Maybe have an argument in the function to round to nearest or to round up/down?

     

    Can someone help me build a function to do this? It would be greatly appreciated!

     

    Thank you!

  3. I have an array of hexadecimal color codes:

     

    Array
    (
        [0] => 2060A0
        [1] => 204080
        [2] => 206080
        [3] => 000000
        [4] => A0A0A0
        [5] => C0C0C0
        [6] => 808080
        [7] => E0E0E0
        [8] => 404040
        [9] => 80A0A0
        [10] => 202020
        [11] => 002020
    )
    

     

    I would like to sort the array by color.  I tried a natsort() and that didn't work the way I would have liked.

    Does anyone have any ideas on how to accomplish this?

     

    Thanks!

  4. Thank you!  Can you help me debug what I have found?

     

    PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20060613/pdo_mysql.so' - (null) in Unknown on line 0
    

     

    I also found this from a few days ago, but I haven't seen it in the logs recently.

    dyld: Library not loaded: /usr/local/mysql/lib/libmysqlclient.16.dylib
      Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20060613/pdo_mysql.so
      Reason: no suitable image found.  Did find:
    /usr/local/mysql/lib/libmysqlclient.16.dylib: mach-o, but wrong architecture
    

     

    Any ideas?

  5. <?php
    $test = 'Paths.Images.Icons';
    $out = array();
    foreach (array_reverse(explode('.',$test)) as $v) $out = array($v => $out);
    print_r($out);
    ?>

     

    Wow!  That is genus and so simple!

     

    Also, I compared the two slightly different functions, see below.

    <?php
    // Sasa's Function
    function strToNestedArray($string) {
       $out = array();
       foreach (array_reverse(explode('.',$string)) as $v) $out = array($v => $out);
       return $out;
    }
    
    // uniflare Function
    function str_to_nested_array($string) {
      $rVerse = array_reverse(explode('.',$string));
      foreach ($rVerse as $v) $out = array($v => $out);
      return $out;
    }
    
    $str = "path.to.something.that.is.really.neat";
    
    echo "100k call * 10 benchmarking: <br/><br/>";
    echo "Sasa's Test<br/>";
    for ($y = 0; $y < 10; $y++) {
    $start = microtime(true);
    for ($x = 0; $x < 100000; $x++) {
       $structure = strToNestedArray($str);
    }
    $time = microtime(true) - $start;
    echo $time . "<br/>";
    }
    
    echo "<br/>uniflare 's Test<br/>";
    for ($y = 0; $y < 10; $y++) {
    $start = microtime(true);
    for ($x = 0; $x < 100000; $x++) {
       $array = str_to_nested_array($str);
    }
    $time = microtime(true) - $start;
    echo $time . "<br/>";
    }
    

     

    Here are the results:

    100k call * 10 benchmarking:

     

    Sasa's Test

    0.581806898117

    0.576666116714

    0.580965995789

    0.581721782684

    0.580982923508

    0.579081058502

    0.579075813293

    0.578878879547

    0.578855037689

    0.580253124237

     

    uniflare's Test

    0.655313968658

    0.654915094376

    0.655946016312

    0.654715061188

    0.655534029007

    0.662548065186

    0.647897958755

    0.648191213608

    0.6495449543

    0.650224924088

     

    I really appreciate everyone's help and snippets.  Thanks everyone!

  6. I have a string that I need converted to a nested array.  See code below:

    // Input string
    $string = 'Paths.Images.Icons';
    
    /*
    Need the following back:
    Array
    (
        [Paths] => Array
        (
            [images] => Array
            (
                [icons] => Array
                (
                )
            )
        )
    )
    
    */
    
    

     

    I need a function that will parse the input string and generate a nested array based on the periods in the input string.

     

    Can someone help me create a function to do this?

     

    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.