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.
Ad

Recommended

March2004-CPerlRun
March2004-CPerlRun
tutorialsruby
 
PHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM i
Alan Seiden
 
What's New in WebSphere Application Server
What's New in WebSphere Application Server
COMMON Europe
 
Compiling the Compiler
Compiling the Compiler
COMMON Europe
 
Workload Groups overview updates
Workload Groups overview updates
COMMON Europe
 
Why i - Common Europe 2012
Why i - Common Europe 2012
COMMON Europe
 
The Ruby OpenSSL extension
The Ruby OpenSSL extension
COMMON Europe
 
Using Ruby on IBM i (i5/OS)
Using Ruby on IBM i (i5/OS)
COMMON Europe
 
IBM Systems Director Navigator for i
IBM Systems Director Navigator for i
COMMON Europe
 
IBM i Trends & Directions Common Europe 2012
IBM i Trends & Directions Common Europe 2012
COMMON Europe
 
IBM i Technology Refreshes Overview 2012 06-04
IBM i Technology Refreshes Overview 2012 06-04
COMMON Europe
 
IBM i 7.1 & TRs CEC 2012
IBM i 7.1 & TRs CEC 2012
COMMON Europe
 
DB2 Web Query whats new
DB2 Web Query whats new
COMMON Europe
 
Access client solutions overview
Access client solutions overview
COMMON Europe
 
What's new with Zend server
What's new with Zend server
COMMON Europe
 
RPG investment
RPG investment
COMMON Europe
 
Open source report writing tools for IBM i Vienna 2012
Open source report writing tools for IBM i Vienna 2012
COMMON Europe
 
Moving 5.4 to 7.1 AB
Moving 5.4 to 7.1 AB
COMMON Europe
 
Introduction to My SQL
Introduction to My SQL
COMMON Europe
 
IBM CEC 2012 Storage june 11, 2012
IBM CEC 2012 Storage june 11, 2012
COMMON Europe
 
Getting started with PHP on IBM i
Getting started with PHP on IBM i
COMMON Europe
 
Developing mobile applications for i using open source tools Venna 2012
Developing mobile applications for i using open source tools Venna 2012
COMMON Europe
 
DB2 for i 7.1 - Whats New?
DB2 for i 7.1 - Whats New?
COMMON Europe
 
Common Europe SAP on i for beginners
Common Europe SAP on i for beginners
COMMON Europe
 
Business value of PHP
Business value of PHP
COMMON Europe
 
AD for i in modern world
AD for i in modern world
COMMON Europe
 
What you-need-to-know-to-do successful-upgrades
What you-need-to-know-to-do successful-upgrades
COMMON Europe
 
Tips n-tricks to improve performance and reduce disk space
Tips n-tricks to improve performance and reduce disk space
COMMON Europe
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 

More Related Content

More from COMMON Europe (20)

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

Recently uploaded (20)

Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
Ad

Php arrays for RPG programmers

  • 1. PHP Arrays for RPG Programmers Function Junction Mike Pavlak Solutions Consultant [email protected] 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 [email protected] mike p@zend com Please fill out your Session Evaluation! 41 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.