Jump to content

Search the Community

Showing results for tags 'optimization'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Donation Link

Found 2 results

  1. Hello, Have an associative array of variable length and variable key names. The POST array can have the following structure, where [rec_n] can have one or many elements. : $_POST Array ( [rec_1769057] => on [rec_1768743] => on [ponumb] => D000000034 [strnbr] => 100 ) The 'n' is a variable SKU number and concatenated from a select statement. There are thousands of SKUs. PONUMB and STRNBR are static and will always be at the end of the array. I have an algorithm for slicing this array into two separate arrays. skuitems Array ( [rec_1769057] => on [rec_1768743] => on ) postrnbr Array ( [ponumb] => D000000034 [strnbr] => 100 ) The two arrays are then assigned to a $params array one for each update statement... $params Array ( [0] => Array ( [0] => 1768743 [1] => D000000034 [2] => 100 ) [1] => Array ( [0] => 1769057 [1] => D000000034 [2] => 100 )) I would like to accomplish the above in one go... At present the solution has and O(2) notation. Here is the algorithm that works, but seems clunky to me. if( isset($postar) && is_array($postar)) { // first order of mag. $cnt = count($postar) - 2; // total minus last two elements $postrnbr = array_slice( $postar, -2, 2 ); // always ponumb and strnbr $skuitems = array_slice($postar, 0, $cnt); // will be one or more sku items $skukeys = array_keys($skuitems); $qparams = array(); //bind params for update statement foreach($skukeys as $sku) { // second order of mag. $skusplit = explode("_",$sku); // ie Array( [0]=>rec, [1]=>1234545 ) $qparams[] = array($skusplit[1], $postrnbr['ponumb'], $postrnbr['strnbr']); } } Thanks in advance! rwhite35
  2. Q: Should instancing an object be held off until needed - or - instanced early and held in memory until (it may/or may not) be called? Here is an example of the type situation where an custom error reporting class is instanced only when some test has failed. The error reporting is for authorized users running an application from protected sub sections(RESTish solution). /* * check form input and $_FILES upload * if test fails, instance errorwrapper::factory object and call errorReport method * testfilesize function, compares file size limit, set pass1 to true on success * testfiletype function, compares file to allowed MIME types, set pass2 to true on success * svalidate returns array $filteres, sanitized input on success, error message(s) on fail * param boolean $pass[1,2], set initial test condition * param int MAX_FILE_SIZE, constant defines max file size allowed. */ $pass1 = false; $pass2 = false; if(isset($_FILES)) { $ftype = $_FILES['img_file']['type']; $fsize = $_FILES['img_file']['size']; testfilesize($pass1,MAX_FILE_SIZE,$fsize); testfiletype($pass2,$ftype); } if($pass1 == false) { $erparams=array('cat'=>3,'src'=>"addform_control",'ref'=>"addform",'fault'=>"over file size limit"); $errObj=errorwrapper::factory($erparams); $errObj->errorReport(); exit(); } elseif ($pass2 == false) { $erparams=array('cat'=>3,'src'=>"addform_control",'ref'=>"addform",'fault'=>"illegal file type"); $errObj=errorwrapper::factory($erparams); $errObj->errorReport(); exit(); } /* * process form input, all fields checked before returning filteres * could report multiple errors, mode sets level of sanitization. */ $filteres = svalidate($_POST,$mode=1); if($filteres['exit']==1) { foreach($filteres['err'] as $err) { $mes .= $err."\n"; } $erparams=array('cat'=>2,'src'=>"addfo",'ref'=>"list_viewer",'fault'=>$mes); $errObj=errorwrapper::factory($erparams); $errObj->errorReport(); exit(); } else { //continue processing here, error checking over } In this case, the object $errObj is only instanced on a failed condition. However, $errObj could be instantiated before the conditional test and only calls the method when there is a failed condition. It seems like "six to one half dozen" but these applications are large and complex, so I'm looking to squeeze out any worthwhile optimization. Thanks for considering the question.
  • 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.