SlideShare a Scribd company logo
1 of 39
Download to read offline
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

More from COMMON Europe

IBM Systems Director Navigator for i
IBM Systems Director Navigator for iIBM Systems Director Navigator for i
IBM Systems Director Navigator for iCOMMON Europe
 
IBM i Trends & Directions Common Europe 2012
IBM i Trends & Directions Common Europe 2012IBM i Trends & Directions Common Europe 2012
IBM i Trends & Directions Common Europe 2012COMMON Europe
 
IBM i Technology Refreshes Overview 2012 06-04
IBM i Technology Refreshes Overview 2012 06-04IBM i Technology Refreshes Overview 2012 06-04
IBM i Technology Refreshes Overview 2012 06-04COMMON Europe
 
IBM i 7.1 & TRs CEC 2012
IBM i 7.1 & TRs CEC 2012IBM i 7.1 & TRs CEC 2012
IBM i 7.1 & TRs CEC 2012COMMON Europe
 
DB2 Web Query whats new
DB2 Web Query whats newDB2 Web Query whats new
DB2 Web Query whats newCOMMON Europe
 
Access client solutions overview
Access client solutions overviewAccess client solutions overview
Access client solutions overviewCOMMON Europe
 
What's new with Zend server
What's new with Zend serverWhat's new with Zend server
What's new with Zend serverCOMMON Europe
 
Open source report writing tools for IBM i Vienna 2012
Open source report writing tools for IBM i  Vienna 2012Open source report writing tools for IBM i  Vienna 2012
Open source report writing tools for IBM i Vienna 2012COMMON Europe
 
Moving 5.4 to 7.1 AB
Moving 5.4 to 7.1 ABMoving 5.4 to 7.1 AB
Moving 5.4 to 7.1 ABCOMMON Europe
 
Introduction to My SQL
Introduction to My SQLIntroduction to My SQL
Introduction to My SQLCOMMON Europe
 
IBM CEC 2012 Storage june 11, 2012
IBM CEC 2012 Storage june 11, 2012IBM CEC 2012 Storage june 11, 2012
IBM CEC 2012 Storage june 11, 2012COMMON Europe
 
Getting started with PHP on IBM i
Getting started with PHP on IBM iGetting started with PHP on IBM i
Getting started with PHP on IBM iCOMMON Europe
 
Developing mobile applications for i using open source tools Venna 2012
Developing mobile applications for i using open source tools  Venna 2012Developing mobile applications for i using open source tools  Venna 2012
Developing mobile applications for i using open source tools Venna 2012COMMON Europe
 
DB2 for i 7.1 - Whats New?
DB2 for i 7.1 - Whats New?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 beginnersCommon Europe SAP on i for beginners
Common Europe SAP on i for beginnersCOMMON Europe
 
Business value of PHP
Business value of PHPBusiness value of PHP
Business value of PHPCOMMON Europe
 
AD for i in modern world
AD for i in modern worldAD for i in modern world
AD for i in modern worldCOMMON Europe
 
What you-need-to-know-to-do successful-upgrades
What you-need-to-know-to-do successful-upgradesWhat you-need-to-know-to-do successful-upgrades
What you-need-to-know-to-do successful-upgradesCOMMON Europe
 
Tips n-tricks to improve performance and reduce disk space
Tips n-tricks to improve performance and reduce disk spaceTips n-tricks to improve performance and reduce disk space
Tips n-tricks to improve performance and reduce disk spaceCOMMON Europe
 

More from COMMON Europe (20)

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

Recently uploaded

Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

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.