/**
* Cleans up multi-dimensional arrays.
* 1st dimension is a simple index
* 2nd dimension includes the desired keys
*
* @param mixed $array
* @param mixed $keysToInclude
*/
public function cleanUpArray($array, $keysToInclude) {
$returnArray = array();
$i = 0;
foreach($array as $item){
foreach($keysToInclude as $key){
$returnArray[$i][$key] = $item[$key];
}
$i++;
}
return $returnArray;
}Filter Some Keys in Multi Dimensional Arrays in Php
·1 min
Related
MySQL Update If Exist Else Insert Procedure
·1 min
Are you tired of checking data in your code before inserting? Well MySQL procedures are here to the rescue. This simple procedure shows how you can do that:
CREATE PROCEDURE ` update_insert_user ` ( IN uid2 int ) BEGIN DECLARE last_login2 DATETIME; SELECT ` last_login ` INTO last_login2 FROM ` user ` WHERE ` uid ` = uid2 LIMIT 1 ; IF last_login2 IS NULL THEN INSERT INTO ` user ` ( ` uid ` , ` last_login ` ) values (uid2, now()); ELSE UPDATE ` user ` SET ` last_login ` = now() WHERE ` uid ` = uid2 LIMIT 1 ; END IF ; END
Codeigniter Creates a New Session With Each Page Load
·1 min
Just spent 3 hours debugging a session bug in my webapp. CodeIgniter was creating a brand new session with each page load. The issue was a misconfiguration with my config file.
Fix was simple, in /application/config/config.php, make sure the correct domain is set for $config['cookie_domain'].
Codeigniter Out of Memory Error
·1 min
Query Saving is a feature of CI’s database class that stores the results of every query in memory until the controller is finished executing. As it turns out, in version 1.6.0, the ability to turn this off was added. The addition of the save_queries variable is listed in the Change Log, but as of the latest release of 2.0.0 last week, it still hasn’t made the documentation.
$this->db->save_queries = FALSE; via Undocumented CodeIgniter | Green Egg Media.