SlideShare a Scribd company logo
PHP Arrays for RPG Programmers

                       Function Junction
Mike Pavlak
Solutions Consultant
mike.p@zend.com
mike 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 don't 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 up
to 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 MCPressonline
or at fine bookstores everywhere




                     © All rights reserved. Zend Technologies, Inc.
Join us at ZendCon
The 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.

More Related Content

PDF
March2004-CPerlRun
PDF
PHP Toolkit from Zend and IBM: Open Source on IBM i
PDF
What's New in WebSphere Application Server
PDF
Compiling the Compiler
PDF
Workload Groups overview updates
PDF
Why i - Common Europe 2012
PDF
The Ruby OpenSSL extension
PDF
Using Ruby on IBM i (i5/OS)
March2004-CPerlRun
PHP Toolkit from Zend and IBM: Open Source on IBM i
What's New in WebSphere Application Server
Compiling the Compiler
Workload Groups overview updates
Why i - Common Europe 2012
The Ruby OpenSSL extension
Using Ruby on IBM i (i5/OS)

More from COMMON Europe (20)

PDF
IBM Systems Director Navigator for i
PDF
IBM i Trends & Directions Common Europe 2012
PDF
IBM i Technology Refreshes Overview 2012 06-04
PDF
IBM i 7.1 & TRs CEC 2012
PDF
DB2 Web Query whats new
PDF
Access client solutions overview
PDF
What's new with Zend server
PDF
RPG investment
PDF
Open source report writing tools for IBM i Vienna 2012
PDF
Moving 5.4 to 7.1 AB
PDF
Introduction to My SQL
PDF
IBM CEC 2012 Storage june 11, 2012
PDF
Getting started with PHP on IBM i
PDF
Developing mobile applications for i using open source tools Venna 2012
PDF
DB2 for i 7.1 - Whats New?
PPT
Common Europe SAP on i for beginners
PDF
Business value of PHP
PDF
AD for i in modern world
PDF
What you-need-to-know-to-do successful-upgrades
PDF
Tips n-tricks to improve performance and reduce disk space
IBM Systems Director Navigator for i
IBM i Trends & Directions Common Europe 2012
IBM i Technology Refreshes Overview 2012 06-04
IBM i 7.1 & TRs CEC 2012
DB2 Web Query whats new
Access client solutions overview
What's new with Zend server
RPG investment
Open source report writing tools for IBM i Vienna 2012
Moving 5.4 to 7.1 AB
Introduction to My SQL
IBM CEC 2012 Storage june 11, 2012
Getting started with PHP on IBM i
Developing mobile applications for i using open source tools Venna 2012
DB2 for i 7.1 - Whats New?
Common Europe SAP on i for beginners
Business value of PHP
AD for i in modern world
What you-need-to-know-to-do successful-upgrades
Tips n-tricks to improve performance and reduce disk space
Ad

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Machine learning based COVID-19 study performance prediction
PDF
Empathic Computing: Creating Shared Understanding
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPT
Teaching material agriculture food technology
PDF
NewMind AI Monthly Chronicles - July 2025
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Big Data Technologies - Introduction.pptx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
NewMind AI Weekly Chronicles - August'25 Week I
Advanced methodologies resolving dimensionality complications for autism neur...
Mobile App Security Testing_ A Comprehensive Guide.pdf
MYSQL Presentation for SQL database connectivity
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Machine learning based COVID-19 study performance prediction
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Teaching material agriculture food technology
NewMind AI Monthly Chronicles - July 2025
The AUB Centre for AI in Media Proposal.docx
Network Security Unit 5.pdf for BCA BBA.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Ad

Php arrays for RPG programmers

  • 1. PHP Arrays for RPG Programmers Function Junction Mike Pavlak Solutions Consultant mike.p@zend.com mike p@zend com (815) 722 3454 © All rights reserved. Zend Technologies, Inc.
  • 2. 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
  • 3. 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
  • 4. 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
  • 5. Introducing PHP Arrays © All rights reserved. Zend Technologies, Inc.
  • 6. 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
  • 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 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
  • 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 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
  • 9. 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
  • 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 to il • 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 l t if (or ti !) | 13 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
  • 14. 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
  • 15. Got Doc? php.net/array php 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 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
  • 18. 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
  • 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 – 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
  • 20. 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 don't 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 up to RPG © All rights reserved. Zend Technologies, Inc.
  • 22. 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
  • 23. Simple Array Search (Lookup) RPG PHP I found her in position==> 2 | 23 © All rights reserved. Zend Technologies, Inc. 02/04/ 10
  • 24. 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
  • 25. 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
  • 26. More functions in PHP © All rights reserved. Zend Technologies, Inc.
  • 27. 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
  • 28. Navigate the array…Thanks 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… • <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
  • 36. Code for debug debug… © All rights reserved. Zend Technologies, Inc.
  • 37. 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 MCPressonline or at fine bookstores everywhere © All rights reserved. Zend Technologies, Inc.
  • 38. Join us at ZendCon The 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.
  • 39. 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.