• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Php arrays for RPG programmers
 

Php arrays for RPG programmers

on

  • 3,145 views

COMMON Europe Congress 2012 - Vienna

COMMON Europe Congress 2012 - Vienna

Statistics

Views

Total Views
3,145
Views on SlideShare
3,145
Embed Views
0

Actions

Likes
0
Downloads
14
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Php arrays for RPG programmers Php arrays for RPG programmers Presentation Transcript

    • PHP Arrays for RPG Programmers Function JunctionMike PavlakSolutions Consultantmike.p@zend.commike p@zend com(815) 722 3454 © All rights reserved. Zend Technologies, Inc.
    • PHP Sessions Sun 11:30 AM • What’s New with Zend Server Sun 1:30 PM • Business Value of PHP Sun 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 Store Tue 11 30 A 11:30 AM • PHP Arrays for the RPG Programmer| 2 Copyright © 2009 Zend Technologies, Inc, All rights reserved © All rights reserved. Zend Technologies, Inc. 02/03/ 10
    • Agenda • Introduce arrays in PHP y • 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
    • Why are we talking about arrays? • Fastest method for manipulating ordered sets p g • 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 of a elements that are accessed by indexing| 4 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
    • Introducing PHP Arrays © All rights reserved. Zend Technologies, Inc.
    • Data Type Review: 8 Data Types • Scalar • String “the quick brown fox...”, ‘123456’ • Integer 860, -9, 57009 • Floating point 19.99, 29.99, 3.1412 • Boolean true, false • Compound • Array [0] => 0 [1] => 1 [2] => 1 [3] => 2 [4] => 3… • Object OOP • Special • Resource Handle • Null Something that not nothing (empty set)| 6 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
    • 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 t 2’ ’Sh ’ • Associative ‘Cartoon3’=>’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
    • 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 t 2’ ’Sh ’ • Associative ‘Cartoon3’=>’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
    • Enumerated array Code: Output: Array one: Array ( [0] => Scooby [1] => Shaggy [2] => Daphne [3] => Fred [4] => Velma )| 9 © All rights reserved. Zend Technologies, Inc. 02/04/ 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
    • 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
    • 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 to il • Example adding element:| 12 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
    • Removing elements & reducing the array • array_pop removes element from the end • unset removes an element you specify ( entire array!) t l t if (or ti !)| 13 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
    • Trivia points • Really only one type of array…associative • D t content i non-restrictive, any d t t Data t t is t i ti data 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
    • Got Doc? php.net/array php net/array| 15 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
    • Review RPG Arrays © All rights reserved. Zend Technologies, Inc.
    • In the beginning beginning… • Indicators were the only ordered set • Original RPG and RPG II Name Indicators Notes Numbered *IN01-*IN99 IN01- IN99 Gen purpose Command Key *INKA - *INKY No “O” Halt H1-H9 Error recovery Matching M1-M9, MR Matching records Control L1-L9 Level Breaks External U1 U8 U1-U8 Switches Cycle 1P, LR, OA-OG, OV Printing| 17 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
    • And then then… • RPG II - Then came simple arrays. • Predefined length • Single variable data type • Built in E specs E-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
    • 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 – BIF’s : %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
    • From the i7 1 manual i7.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? kidding…Still? • 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
    • How PHP matches upto RPG © All rights reserved. Zend Technologies, Inc.
    • Array shootout • Base functions • RPG has about a dozen op codes and BIF’s (Variations on BIF’s) op-codes • Many op-codes can manipulate array content • PHP has 75 functions www php net/array www.php.net/array • Size • RPG has limits 16 773 104 as if i7 1 (elements & bytes) limits, 16,773,104 i7.1 • PHP has no practical limits, No “array index overflow” error • RPG array must be defined, PHP grows dynamically (CT <= 100) defined • Type • RPG uses static typing (one type, one length) type • PHP is dynamically typed (Each element can be different)| 22 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
    • Simple Array Search (Lookup) RPG PHP I found her in position==> 2| 23 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
    • Simple traverse RPG Scooby is the index value 0 Shaggy is the index value 1 PHP Daphne is the index value 2 Fred is the index value 3 Velma is the index value 4| 24 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
    • RPG to PHP function map Function F ti RPG PHP Notes N t Search %LOOKUP array_search Sum %XFOOT array sum y_ Array prod can multiply y_p py Get portion %SUBARR array_slice Substring an array by chunks Sort SORTA asort, arsort PHP sequence dynamic Move M MOVEA array_slice li Substring by h S b t i b character t Count %ELEM count Get number of elements| 25 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
    • More functions in PHP © All rights reserved. Zend Technologies, Inc.
    • Interesting functions • How to move around the array y • 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
    • Navigate the array…Thanks Jon! array Thanks| 28 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
    • Mix it up with a shuffle| 29 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
    • Consolidate, Consolidate clean and sort arrays| 30 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
    • Sort Multiple Arrays at once!| 31 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
    • Manipulate all elements of an array| 32 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
    • 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
    • Debugging Arrays © All rights reserved. Zend Technologies, Inc.
    • Display the array formatted formatted… • <pre> presents text in fixed format font • Lik courier-new for green b reports conversions Like i f bar t i • Used inside many HTML elements| 36 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
    • Code for debug debug… © All rights reserved. Zend Technologies, Inc.
    • New book, new printing, same great stuff! book printing Kevin Schroeder from Zend’s Global Services Group with Jeff Ol J ff Olen, co-author of… th f Get yours at MCPressonlineor at fine bookstores everywhere © All rights reserved. Zend Technologies, Inc.
    • Join us at ZendConThe premier PHP conference!October 22-25, 2012 – Santa Clara, CA Conference Themes Conference Highlights PHP in 2012 - The latest PHP technologies and tools • Sessions focused on how to best develop and deploy PHP Learn how to leverage the latest mobile, HTML 5, testing and PHP best practices • Sessions designed for all knowledge levels Zend Framework 2 - Hit the ground running • Intensive tutorials for accelerated learning Learn how to build faster, more modular and more expandable • PHP Certification crash courses and testing applications • Exhibit hall showcasing the latest products Development & The Cloud – A love story Learn how the latest developments in cloud-based services services, • Special networking opportunities during meals and events infrastructure and best practices can benefit you www.zendcon.com © All rights reserved. Zend Technologies, Inc.
    • Q&A www.zend.com www zend com mike.p@zend.com mike p@zend com Please fill out your Session Evaluation!41 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.