Skip to content

Instantly share code, notes, and snippets.

View sohelrana820's full-sized avatar
💭
I may be slow to respond.

Sohel Rana sohelrana820

💭
I may be slow to respond.
View GitHub Profile
<?php
/**
* @Author Shaharia Azam
* @Author URL http://www.shahariaazam.com
*
* @Description this function will make a .zip folder by adding multiple files.
* @link http://php.net/manual/en/book.zip.php
*
* @param array $SourceFiles
* @param string $ZipDestination

Why objects (usually) use less memory than arrays in PHP

This is just a small post in response to [this tweet][tweet] by Julien Pauli (who by the way is the release manager for PHP 5.5). In the tweet he claims that objects use more memory than arrays in PHP. Even though it can be like that, it's not true in most cases. (Note: This only applies to PHP 5.4 or newer.)

The reason why it's easy to assume that objects are larger than arrays is because objects can be seen as an array of properties and a bit of additional information (like the class it belongs to). And as array + additional info > array it obviously follows that objects are larger. The thing is that in most cases PHP can optimize the array part of it away. So how does that work?

The key here is that objects usually have a predefined set of keys, whereas arrays don't:

@sohelrana820
sohelrana820 / Batch.php
Last active December 14, 2015 18:39
This is Batch tracker
<?php
public function Batch($BatchNo){
if($BatchNo==1){
return "First Batch";
}
else if($BatchNo==2){
return "Second Batch";
}
else if($BatchNo==3){
return "Third Batch";
@sohelrana820
sohelrana820 / index.html
Created March 16, 2013 21:08
LESS CSS Practice
<!DOCTYPE html>
<html>
<head>
<title>LESS Practice</title>
<link rel="stylesheet/less" type="text/css" href="styles.less" />
<script src="less.js" type="text/javascript"></script>
</head>
<body>
<h2 class="h2">Hello World</h2>
</body>
<?php
$MyArray = array('Name'=>'Rana','ID'=>'092-15-820','Batch'=>'23');
// If you want to echo the name just write "echo $MyArray['Name']";
echo $MyArray['Name'];
//Another way
$MyArray2 = array('Rana','092-15-820','23');
// If you want to echo the name just write "echo $MyArray2[0]";
echo $MyArray2[0];
@sohelrana820
sohelrana820 / MyClass.php
Created August 21, 2013 05:02
Simple Example of PHP Autoloading Classes
<?php
/**
* @Author: Sohel Rana
* @URI : http://www.sohelranabd.com
* @Description: This is simple example of PHP auto loading class
*/
class MyClass // Creating First Class
{
public function getValue(){
@sohelrana820
sohelrana820 / MyClass.php
Created August 21, 2013 05:09
PHP Autoloading Classes by Using spl_autoload_register() methos
<?php
/**
* @Author: Sohel Rana
* @URI : http://www.sohelranabd.com
* @Description: This is simple example of PHP auto loading class
*/
class MyClass // Creating First Class
{
public function getValue(){
jQuery(function($) {
$('form[data-async]').live('submit', function(event) {
var $form = $(this);
var $target = $($form.attr('data-target'));
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(),
public function imgValidate()
{
$validateImg = array(
'image' => array(
'isImage' => array(
'rule' => array('isImage'),
'message' => 'Please provide an image!',
),
'dimension' => array(
'rule' => array('dimension', 320, 100),
public function uploadImage($filename, $document, $path)
{
$ext = $this->Img->ext($document['name']);
$origFile = $filename. '.'. $ext;
$targetDir = WWW_ROOT . $path;
$upload = $this->Img->upload($document['tmp_name'], $targetDir, $origFile);
if ($upload == 'Success') {
return 'category/'.$origFile;
}
return false;