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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
AgentCoreとHuman in the Loop
har1101
5
220
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
940
Fluid Templating in TYPO3 14
s2b
0
130
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
240
Grafana:建立系統全知視角的捷徑
blueswen
0
320
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
370
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
0
900
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
590
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
130
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
420
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
140
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
141
7.3k
Paper Plane
katiecoart
PRO
0
46k
YesSQL, Process and Tooling at Scale
rocio
174
15k
The browser strikes back
jonoalderson
0
360
So, you think you're a good person
axbom
PRO
2
1.9k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
230
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.8k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
180
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Fireside Chat
paigeccino
41
3.8k
Chasing Engaging Ingredients in Design
codingconduct
0
110
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
0
430
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