zf2 how arrays will save your project
TRANSCRIPT
![Page 1: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/1.jpg)
Zend Framework2How arrays will save your project
in it2PROFESSIONAL PHP SERVICES
![Page 2: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/2.jpg)
Michelangelo van DamPHP Consultant, Community Leader & Trainer
http
s://w
ww.
flick
r.com
/pho
tos/
akra
bat/8
7843
1881
3
![Page 3: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/3.jpg)
ScheduleIntroduction to ZF2
The array
Challenges in development
Solutions offered in ZF2
More options
![Page 4: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/4.jpg)
ScheduleIntroduction to ZF2
The array
Challenges in development
Solutions offered in ZF2
More options
![Page 5: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/5.jpg)
![Page 6: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/6.jpg)
![Page 7: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/7.jpg)
“The Array Framework”
![Page 8: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/8.jpg)
<?php /** * Zend Framework 2 Configuration Settings * */ return array( 'modules' => array( 'Application', 'In2it\\SsoProvider', 'In2it\\Crm\\Dashboard', 'In2it\\Crm\\ContactManager', 'In2it\\Crm\\OrderManager', 'In2it\\Crm\\ProductManager', ), 'module_listener_options' => array( 'module_paths' => array( './module', './vendor' ), 'config_glob_paths' => array( '/home/dragonbe/workspace/Totem/config/autoload/{,*.}{global,local}.php' ), 'config_cache_key' => 'application.config.cache', 'config_cache_enabled' => true, 'module_map_cache_key' => 'application.module.cache', 'module_map_cache_enabled' => true, 'cache_dir' => 'data/cache/' ) );
![Page 9: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/9.jpg)
<?phpnamespace In2it\Crm\Dashboard;
use Zend\ModuleManager\Feature\ConfigProviderInterface; use Zend\Mvc\ModuleRouteListener; use Zend\Mvc\MvcEvent;
class Module implements ConfigProviderInterface { public function getAutoloaderConfig() { return array( 'Zend\Loader\ClassMapAutoloader' => array( __DIR__ . '/autoload_classmap.php', ), 'Zend\Loader\StandardAutoloader' => array( 'namespaces' => array( __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, ), ), ); }
public function getConfig() { return include __DIR__ . '/config/module.config.php'; } }
![Page 10: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/10.jpg)
http
s://w
ww.
flick
r.com
/pho
tos/
dasp
rid/8
1479
8630
7
![Page 11: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/11.jpg)
Yaml
XML
INI
CSV PHP
![Page 12: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/12.jpg)
PHP
![Page 13: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/13.jpg)
ScheduleIntroduction to ZF2
The array
Challenges in development
Solutions offered in ZF2
More options
![Page 14: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/14.jpg)
array_change_key_case array_chunk array_column
array_combine array_count_values
array_diff_assoc array_diff_key
array_diff_uassoc array_diff_ukey
array_diff array_fill_keys
array_fill array_filter array_flip
array_intersect_assoc array_intersect_key
array_intersect_uassoc array_intersect_ukey
array_intersect array_key_exists
array_keys array_map
array_merge_recursive array_merge
array_multisort array_pad array_pop
array_product
array_push array_rand
array_reduce array_replace_recursive
array_replace array_reverse array_search
array_shift array_slice
array_splice array_sum
array_udiff_assoc array_udiff_uassoc
array_udiff array_uintersect_assoc array_uintersect_uassoc
array_uintersect array_unique array_unshift array_values
array_walk_recursive array_walk
array arsort asort
compact count
current
each end
extract in_array
key_exists key
krsort ksort list
natcasesort natsort
next pos prev
range reset rsort
shuffle sizeof sort
uasort uksort usort
![Page 15: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/15.jpg)
Do you know them?
![Page 16: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/16.jpg)
array_search array_filter
? ? ? ??
? ? ??
??
???
? ? ?
![Page 17: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/17.jpg)
count array_sum
array_product
? ? ? ??
? ? ??
??
???
? ? ?
![Page 18: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/18.jpg)
array_diff array_intersect array_merge
? ? ? ??
? ? ??
??
???
? ? ?
![Page 19: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/19.jpg)
// Let's take one value out of our array $array = ['apple', 'banana', 'chocolate'];
$newArray = []; foreach ($array as $value) { if ('banana' !== $value) { $newArray[] = $value; } } echo implode(', ', $newArray);
// Outputs: apple, chocolate
![Page 20: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/20.jpg)
<?php
// Let's take one value out of our array $array = ['apple', 'banana', 'chocolate'];
// I keep an ignore list as well $ignore = ['banana'];
// Ready for magic? echo implode(', ', array_diff($array, $ignore));
// Outputs: apple, chocolate
![Page 21: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/21.jpg)
<?php
// I have one associative array $array = ['a' => 'apple', 'b' => 'banana', 'c' => 'chocolate'];
// And a similar value array $similar = ['banana', 'chocolate'];
// I need to get the keys of similar items from original array $newSimilar = []; foreach ($array as $key => $value) { if (in_array($value, $similar)) { $newSimilar[$key] = $value; } } $similar = $newSimilar; unset ($newSimilar);
var_dump($similar);
/* Outputs: array(2) { 'b' => string(6) "banana" 'c' => string(9) "chocolate" } */
![Page 22: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/22.jpg)
<?php
// I have one associative array $array = ['a' => 'apple', 'b' => 'banana', 'c' => 'chocolate'];
// And a similar value array $similar = ['banana', 'chocolate'];
// I need to get the keys of similar items from original array $similar = array_intersect($array, $similar);
var_dump($similar);
/* Outputs: array(2) { 'b' => string(6) "banana" 'c' => string(9) "chocolate" } */
![Page 23: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/23.jpg)
One more?
![Page 24: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/24.jpg)
<?php
// I have one associative array $array = ['a' => 'apple', 'b' => 'banana', 'c' => 'chocolate'];
// I need to find a given value -> 'chocolate' $search = 'chocolate'; $searchResult = []; foreach ($array as $key => $value) { if ($search === $value) { $searchResult[$key] = $value; } } var_dump($searchResult);
/* Outputs: array(1) { 'c' => string(9) "chocolate" } */
![Page 25: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/25.jpg)
<?php
// I have one associative array $array = ['a' => 'apple', 'b' => 'banana', 'c' => 'chocolate'];
// I need to find a given value -> 'chocolate' $search = 'chocolate'; $searchResult = array_filter($array, function ($var) use ($search) { return $search === $var; }); var_dump($searchResult);
/* Outputs: array(1) { 'c' => string(9) "chocolate" } */
![Page 26: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/26.jpg)
ScheduleIntroduction to ZF2
The array
Challenges in development
Solutions offered in ZF2
More options
![Page 27: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/27.jpg)
Lots of data
![Page 28: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/28.jpg)
Lists of data rows
![Page 29: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/29.jpg)
<?php
$query = "SELECT * FROM `contact` WHERE `age` > ? AND `gender` = ?"; $stmt = $pdo->prepare($query); $stmt->bindParam(1, $cleanAge); $stmt->bindParam(2, $cleanGender); $stmt->execute();
// A resultset of 63,992 entries stored in an array!!! $resultList = $stmt->fetchAll();
![Page 30: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/30.jpg)
<?php
public function getSelectedContacts($age, $gender) { $resultSet = $this->tableGateway->select(array( 'age' => $age, 'gender' => $gender, )); return $resultSet; }
![Page 31: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/31.jpg)
Iterators!!!
![Page 32: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/32.jpg)
Loop with arrays• Data fetching time for 63992 of 250000 records:
2.14 seconds
• Data processing time for 63992 of 250000 records: 7.11 seconds
• Total time for 63992 of 250000 records: 9.25 seconds
• Memory consumption for 63992 of 250000 records: 217.75MB
![Page 33: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/33.jpg)
Loop with Iterators• Data fetching time for 63992 of 250000 records:
0.92 seconds
• Data processing time for 63992 of 250000 records: 5.57 seconds
• Total time for 63992 of 250000 records: 6.49 seconds
• Memory consumption for 63992 of 250000 records: 0.25MB
![Page 34: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/34.jpg)
Loop with Iterators• Data fetching time for 63992 of 250000 records:
0.92 seconds
• Data processing time for 63992 of 250000 records: 5.57 seconds
• Total time for 63992 of 250000 records: 6.49 seconds
• Memory consumption for 63992 of 250000 records: 0.25MB <-> 217.75MB
![Page 35: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/35.jpg)
ScheduleIntroduction to ZF2
The array
Challenges in development
Solutions offered in ZF2
More options
![Page 36: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/36.jpg)
Iterators
![Page 37: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/37.jpg)
Interfaces
![Page 38: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/38.jpg)
Responsibility Separation
![Page 39: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/39.jpg)
Modules
![Page 40: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/40.jpg)
ScheduleIntroduction to ZF2
The array
Challenges in development
Solutions offered in ZF2
More options
![Page 41: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/41.jpg)
–Michelangelo van Dam
“You dislike arrays because you don’t know them well enough to love them”
![Page 42: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/42.jpg)
Links
• Array functions http://php.net/manual/en/ref.array.php
• Iterator http://php.net/manual/en/class.iterator.php
• SPL Iterators and DataStructures http://php.net/spl/
![Page 44: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/44.jpg)
http
s://w
ww.
flick
r.com
/pho
tos/
lwr/1
3442
5422
35
![Page 45: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/45.jpg)
Contact us
in it2PROFESSIONAL PHP SERVICES
Michelangelo van Dam [email protected]
www.in2it.be
PHP Consulting - Training - QA
![Page 46: Zf2 how arrays will save your project](https://reader034.vdocuments.net/reader034/viewer/2022052405/58a426b51a28abec1a8b6dff/html5/thumbnails/46.jpg)
Thank youHave a great conference
http
://w
ww.
flick
r.com
/pho
tos/
drew
m/3
1918
7251
5