Posts Tagged "Advanced PHP"

Get last order of an customer magento

Here is the example code by which you can get last order details into mangento of using email id. $_customer = Mage::getModel('customer/customer'); $_customer->loadByEmail('demo@demo.com'); $orders = Mage::getResourceModel('sales/order_collection') ->addFieldToSelect('*') ->addFieldToFilter('customer_id', $_customer->getId()) ->addAttributeToSort('created_at', 'DESC') ->setPageSize(1); <strong>ID</strong> echo $orders->getFirstItem()->getId(); Shashi Dhar KumarShashi Dhar Kumar Experience in Web/software development including client server and implementation using PHP, XML, MySQL and SQL Server. Experience of working on Apache, Linux projects, Javascript, Ajax, Putty, FTP, Remote Connection, XML parsing, Mod-Rewriting, Payment Gateways and shipping modules, Trouble shooting and…

Read More

50+ PHP tips and tricks

echo is faster than print. Wrap your string in single quotes (’) instead of double quotes (”) is faster because PHP searches for variables inside “…” and not in ‘…’, use this when you’re not using variables you need evaluating in your string. Use sprintf instead of variables contained in double quotes, it’s about 10x faster. Use echo’s multiple parameters (or stacked) instead of string concatenation. Use pre-calculations, set the maximum value for your for-loops before and not in the…

Read More

PHP Type Casting

Contents Types Casting Cast to string Cast to int Cast to binary (PHP6) Cast to unicode (PHP6) Cast to boolean Cast to object Cast to float Check for Type Check String Check INT Check Array Check Object Check Float Check Double Check Real Check Bool Check Buffer Check Binary Check Unicode Check NULL Check Resource Check Scalar The PHP is often referred to as “loosely typed” or “dynaically typed”. What this means is that variable types are detirmined by context….

Read More