Home >Technology >Php arrays for RPG programmers

Php arrays for RPG programmers

Date post:08-May-2015
Category:
View:3,213 times
Download:4 times
Share this document with a friend
Description:
COMMON Europe Congress 2012 - Vienna
Transcript:

2. PHP SessionsSun 11:30 AM Whats New with Zend ServerSun 1:30 PM Business Value of PHPSun 4:00 PM Practical PHP by Example (Leth-Kjaer) Mon 10:00 AM PHP on IBM i: Getting Started Mon 10:00 AM DB Standards in Zend PHP usage (Sielhorst)Tue 10:00 AM MySQL on IBM i, Open Source & DB2 StoreTue 11 30 A11:30 AM PHP Arrays for the RPG Programmer| 2 Copyright 2009 Zend Technologies, Inc, All rightsreserved All rights reserved. Zend Technologies, Inc. 02/03/ 10 3. Agenda Introduce arrays in PHPy Review RPG arrays Compare RPG and PHP array concepts More functions for arrays in PHP Q&A| 3 All rights reserved. Zend Technologies, Inc. 02/04/10 4. Why are we talking about arrays? Fastest method for manipulating ordered sets pg Highly leveraged in PHP development PHP developers take them for granted Available in RPG but long neglected Gap that needs to be closed Array defined:a data structure consisting of a group ofaelements that are accessed by indexing| 4 All rights reserved. Zend Technologies, Inc. 02/04/ 10 5. Introducing PHP Arrays All rights reserved. Zend Technologies, Inc. 6. Data Type Review: 8 Data Types Scalar String the quick brown fox..., 123456 Integer860, -9, 57009 Floating point 19.99, 29.99, 3.1412 Booleantrue, false Compound Array[0] => 0 [1] => 1 [2] => 1 [3] => 2 [4] => 3 Object OOP Special ResourceHandle NullSomething that not nothing (empty set)| 6 All rights reserved. Zend Technologies, Inc. 02/04/10 7. Three types of arrays (PHP 5.3 notation) Enumerated$arrayone = array(Scooby, Shaggy, Daphne, Fred, Velma);Fred Velma ); Simple list$arraytwo = array( Cartoon1=>Scooby, Cartoon2=>Shaggy, C t2 Sh AssociativeCartoon3=>Daphne, Cartoon4=>Fred, Custom key Cartoon5=>Velma );$arraythree = array(array(Scooby, Shaggy, Daphne,Fred, Velma), Multidimensional array(Bugs, Daffy, Tweety,Elmer, Foghorn) ) g) ); Array of arrays| 7 All rights reserved. Zend Technologies, Inc.02/04/10 8. Three types of arrays (PHP 5.4 notation) Enumerated$arrayone = [Scooby, Shaggy, Daphne, Fred, Velma];Fred Velma ]; Simple list$arraytwo = [Cartoon1=>Scooby, Cartoon2=>Shaggy, C t2 Sh AssociativeCartoon3=>Daphne, Cartoon4=>Fred, Custom key Cartoon5=>Velma ];$arraythree = array[[Scooby, Shaggy, Daphne, Fred, Velma], Multidimensional [Bugs, Daffy, Tweety, Elmer, Foghorn] ]; g ] ] Array of arrays| 8 All rights reserved. Zend Technologies, Inc.02/04/10 9. Enumerated arrayCode:Output:Array one: Array ( [0] => Scooby [1] => Shaggy [2] => Daphne [3] => Fred [4] => Velma )| 9 All rights reserved. Zend Technologies, Inc.02/04/ 10 10. Associative array Code: Output: If you have trouble, think CL command parameters: Keyword & Values!!!| 10 All rights reserved. Zend Technologies, Inc. 02/04/ 10 11. Multidimensional array Code: Output: Array three: Array ( [0] => Array ( [0] => Scooby [1] => Shaggy [2] => Daphne [3] => Fred [4] => Velma ) [1] => Array ( [0] => Bugs [1] => Daffy [2] => Tweety [3] => Elmer [4] => Foghorn ) )| 11 All rights reserved. Zend Technologies, Inc.02/04/ 10 12. Adding elements & growing the array PHP Arrays are dynamic C b sized on th fl no need t recompile Can be i d the fly,d toil Example adding element:| 12 All rights reserved. Zend Technologies, Inc. 02/04/ 10 13. Removing elements & reducing the array array_pop removes element from the end unset removes an element you specify ( entire array!) t lt if (or ti !)| 13 All rights reserved. Zend Technologies, Inc. 02/04/ 10 14. Trivia points Really only one type of arrayassociative D t content i non-restrictive, any d t t Data t t ist i tidata types Each element can be different Array sizes change dynamically Supports no known limit of dimensions How much memory is on your machine? Humans like 2 or 3 (Think spreadsheet and workbook) Used heavily in i/o Both index and content can change! Index starts at zero while RPG starts at one| 14 All rights reserved. Zend Technologies, Inc. 02/04/10 15. Got Doc? php.net/arrayphp net/array| 15 All rights reserved. Zend Technologies, Inc. 02/04/10 16. Review RPG Arrays All rights reserved. Zend Technologies, Inc. 17. In the beginningbeginning Indicators were the only ordered set Original RPG and RPG II Name Indicators Notes Numbered *IN01-*IN99 IN01- IN99Gen purpose Command Key*INKA - *INKYNo O Halt H1-H9Error recovery Matching M1-M9, MRMatching records ControlL1-L9Level Breaks External U1 U8U1-U8Switches Cycle1P, LR, OA-OG, OVPrinting| 17 All rights reserved. Zend Technologies, Inc.02/04/10 18. And then then RPG II - Then came simple arrays. Predefined length Single variable data type Built in E specsE-specs Op Codes XFOOT Summing aray MOVEA Move data (Still most extremely powerful) LOKUP Search the array SORTA Gee, I wonder what this does? Seems like things paused here for a while| 18 All rights reserved. Zend Technologies, Inc. 02/04/10 19. Today Today Compile time tables Great for static content Defined below O specs Two dimensional in nature RPG III Multiple Occurrence Data Structure (MODS) Two dimensional feel Still a little clunky RPG IV More Power! V5R1 BIFs : %LOOKUP, %LOOKUPGT, etc. V5R2 DIM for Data Structures; MODS on Steroids! V5R3 %SUBARR is an attempt at dynamic sizing V5R4 XML processing i6.1 DIM up to 16,773,104 i7.1 Sort subfields, Ascend-Descend, (still fixed size )| 19 All rights reserved. Zend Technologies, Inc. 02/04/10 20. From the i7 1 manuali7.1 The first array entry for each record must begin in position 1. PHP starts with zero All elements must be the same length and follow each other with no intervening spaces You must be kidding Still?kiddingStill? If the number of elements in the array as specified on the definition specification is greater than the number of entries provided, the remaining elements are filled with the default values for the data type specified specified. If you dont know the number of elements you will need in an array until runtime, you can define the array with the maximum size, and then use a subset of the array in your program program. PHP is far more dynamic and this message leaves with work-files, still| 20 All rights reserved. Zend Technologies, Inc.02/04/10 21. How PHP matches upto RPG All rights reserved. Zend Technologies, Inc. 22. Array shootout Base functions RPG has about a dozen op codes and BIFs (Variations on BIFs) op-codes Many op-codes can manipulate array content PHP has 75 functions www php net/arraywww.php.net/array Size RPG has limits 16 773 104 as if i7 1 (elements & bytes) limits, 16,773,104i7.1 PHP has no practical limits, No array index overflow error RPG array must be defined, PHP grows dynamically (CT 2| 23 All rights reserved. Zend Technologies, Inc. 02/04/10 24. Simple traverseRPGScooby is the index value 0Shaggy is the index value 1PHP Daphne is the index value 2Fred is the index value 3Velma is the index value 4| 24 All rights reserved. Zend Technologies, Inc. 02/04/ 10 25. RPG to PHP function map Function F tiRPGPHP NotesN t Search%LOOKUParray_search Sum %XFOOT array sumy_Array prod can multiplyy_p py Get portion %SUBARRarray_slice Substring an array by chunks SortSORTAasort, arsort PHP sequence dynamic Move M MOVEAarray_slice li Substring by hS b t i b charactert Count %ELEMcount Get number of elements| 25 All rights reserved. Zend Technologies, Inc.02/04/ 10 26. More functions in PHP All rights reserved. Zend Technologies, Inc. 27. Interesting functions How to move around the arrayy Randomize contents Array housekeeping Move array elements to variables Sort two or more arrays at once Execute a function on each element with no loop! Data file example| 27 All rights reserved. Zend Technologies, Inc. 02/04/ 10 28. Navigate the arrayThanks Jon!array Thanks| 28 All rights reserved. Zend Technologies, Inc. 02/04/ 10 29. Mix it up with a shuffle| 29 All rights reserved. Zend Technologies, Inc. 02/04/ 10 30. Consolidate, Consolidate clean and sort arrays| 30 All rights reserved. Zend Technologies, Inc. 02/04/10 31. Sort Multiple Arrays at once!| 31 All rights reserved. Zend Technologies, Inc. 02/04/10 32. Manipulate all elements of an array| 32 All rights reserved. Zend Technologies, Inc. 02/04/10 33. Get data from a file Loop through data List function copies to variables p Implicit copy, be careful Arrays in PHP like Data Structures in RPG: The workhorse of data manipulation!| 33 All rights reserved. Zend Technologies, Inc. 02/04/10 34. Debugging Arrays All rights reserved. Zend Technologies, Inc. 35. Display the array formatted formatted presents text in fixed format font Lik courier-new for green b reports conversionsLikei f bart i Used inside many HTML elements| 36 All rights reserved. Zend Technologies, Inc. 02/04/10 36. Code for debug debug All rights reserved. Zend Technologies, Inc. 37. New book, new printing, same great stuff!bookprintingKevin Schroeder from Zends Global Services Group withJeff OlJ ff Olen, co-author ofthfGet yours at MCPressonlineor at fine bookstores everywhere All rights reserved. Zend Technologies, Inc. 38. Join us at ZendConThe premier PHP conference!October 22-25, 2012 Santa Clara, CAConferenceThemes ConferenceHighlightsPHP in 2012 - The latest PHP technologies and tools Sessions focused on how to best develop and deploy PHPLearn how to leverage the latest mobile, HTML 5, testing andPHP best practices Sessions designed for all knowledge levelsZend Framework 2 - Hit the ground running Intensive tutorials for accelerated learningLearn how to build faster, more modular and more expandable PHP Certification crash courses and testingapplications Exhibit hall showcasing the latest productsDevelopment & The Cloud A love storyLearn how the latest developments in cloud-based servicesservices, Special networking opportunities during meals and eventsinfrastructure and best practices can benefit you www.zendcon.com All rights reserved. Zend Technologies, Inc. 39. Q&A www.zend.com www zend com [email protected] mike [email protected] com Please fill out your Session Evaluation!41 Insert->Header & Footer All rights reserved. Zend Technologies, Inc.

Click here to load reader

Reader Image
Embed Size (px)
Recommended