Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
PHP Map
Search
Aimeos
September 04, 2020
Programming
1
150
PHP Map
Easy to use and elegant handling for PHP arrays using Map objects
Aimeos
September 04, 2020
Tweet
Share
More Decks by Aimeos
See All by Aimeos
GraphQL vs. JSON:API
aimeos
1
240
Responsive E-Mails
aimeos
0
670
gigacommerce
aimeos
0
3.2k
High performance e-commerce in Laravel
aimeos
0
930
E-Commerce in TYPO3 mit Aimeos (Deutsch)
aimeos
0
460
Aimeos - high performance e-commerce in TYPO3
aimeos
0
320
Aimeos e-commerce components
aimeos
1
210
E-Commerce in TYPO3 - Reloaded
aimeos
0
310
Micro services as architectural concept
aimeos
0
700
Other Decks in Programming
See All in Programming
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
390
ゆくKotlin くるRust
exoego
1
200
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
640
2年のAppleウォレットパス開発の振り返り
muno92
PRO
0
180
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
150
CSC307 Lecture 03
javiergs
PRO
1
470
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
480
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
210
ThorVG Viewer In VS Code
nors
0
670
大規模Cloud Native環境におけるFalcoの運用
owlinux1000
0
250
PostgreSQLで手軽にDuckDBを使う!DuckDB&pg_duckdb入門/osc25hi-duckdb
takahashiikki
0
240
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
5.2k
Featured
See All Featured
First, design no harm
axbom
PRO
2
1.1k
The SEO identity crisis: Don't let AI make you average
varn
0
48
Accessibility Awareness
sabderemane
0
35
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
43
4 Signs Your Business is Dying
shpigford
187
22k
We Have a Design System, Now What?
morganepeng
54
8k
Side Projects
sachag
455
43k
Ethics towards AI in product and experience design
skipperchong
1
170
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Transcript
PHP Array > Map
Aimeos E-Commerce framework
Why?
$list = [ ['id' => '1', 'value' => 'value1'], ['id'
=> '2', 'value' => 'value2'], null ]; Starting point
$list[] = ['id' => '3', 'value' => 'value3']; unset($list[0]); $list
= array_filter($list); sort($list); $pairs = array_column($list, 'value', 'id'); $value = reset($pairs) ?: null; Current way
Solutions
Laravel collections CakePHP collections Arrayy Underscore.php
(ceased) Others
php-map.org
$value = map( $list ) ->push(['id' => '3', 'value' =>
'value3']) ->remove(0) ->filter() ->sort() ->col('value', 'id') ->first(); Using Map
$map[] = ['id' => '3', 'value' => 'value3']; $value =
$map[0]; count($map); foreach($map as $key => value) {} Still possible
More than array
map() new Map() Map::from() Creating maps
map([1, 2, 3]) map(new Map()) map($iterator) map('abc')
Almost all array methods supported Array methods
concat() collapse() duplicates() flat() countBy()
groupBy() Additional methods except() only() pull() take() skip() ...
each() every() nth() pipe() some()
... Accepting closures
$map->each( function( $val, $key ) { echo $key . ':
' . $val; } ); Closure example
concat() every() find() flat() includes()
join() keys() Like Javascript map() pop() push() reduce() reverse() some() ...
Useful methods map([1,2,3])->join(','); // '1,2,3' Map::split('1,2,3'); // map([1,2,3]) map(['a'=>1,'b'=>2])->toUrl(); //
'a=1&b=2' map(['a'=>1,'b'=>2])->toJson(); // '{"a":1,"b":2}'
Fluent interface $map->push( 'value' ) ->remove( 0 ) ->filter() ->sort();
$e = new \RuntimeException('not found'); map([])->first($e); Find or fail
Map::method( 'strrev', function($sep) { return strrev(join($sep, $this->list)); } ); Map::from(['c',
'b', 'a'])->strrev(' > '); // returns 'a > b > c' Custom methods
jQuery style
class MyClass { private $code; private $status = 0; public
function __construct( $code ) { $this->code = $code; } public function setStatus( int $s ) { $this->stat = $s; return $this; } public function getCode() { return $this->code; } } Example class
$objects = Map::from( [ 'a' => new MyClass( 'x' ),
'b' => new MyClass( 'y' ) ] ); Example Map
$result = $objects ->setStatus(1) ->getCode() ->toArray(); Operations on objects
// status of all object is 1 // $result contains:
['a' => 'x', 'b' => 'y'] Result
?
Aimeos php-map.org Twitter: @aimeos facebook.com/Aimeos