Class06 Arrays MIS 3502 Jeremy Shafer Department of MIS

Slides:



Advertisements
Similar presentations
Arrays Strings and regular expressions Basic PHP Syntax CS380 1.
Advertisements

NUMERIC ARRAYS DEBBI HAMNER CIT 336 TEACHING PRESENTATION.
Case, Arrays, and Structures. Summary Slide  Case Structure –Select Case - Numeric Value Example 1 –Select Case - String Value Example  Arrays –Declaring.
Chapter 9 Introduction to Arrays
INTERNET APPLICATION DEVELOPMENT For More visit:
Starter – Homework What were our findings?. Computer Science Constants_variables and data types 2.
Multidimensional Arrays CIT 336. The Basics Explaining Multidimensional Arrays.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Array & Foreach อาร์เรย์และคำสั่งวนลูป. Content 1. Definition and Usage 2. Syntax 3. print_r() Statement 4. For and Foreach 5. Array Functions.
Slide 1 PHP Arrays and User Defined Functions ITWA133.
Arrays.
 An array stores multiple values in one single variable.  Example: Output: I like Honda Civic, BMW and Toyota.
Class01 Course Introduction MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 1/12/2016.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
Visual C# 2005 Using Arrays. Visual C# Objectives Declare an array and assign values to array elements Initialize an array Use subscripts to access.
Class02 More Arrays MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 1/14/2016.
Form Data (part 2) MIS 3502, Fall 2015 Brad N Greenwood, PhD Department of MIS Fox School of Business Temple University 11/10/2015 Slide 1.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
Arrays and Collections
Sessions and cookies MIS 3501 Jeremy Shafer Department of MIS
Arrays.
Form Data (part 2) MIS 3502, Fall 2015 Jeremy Shafer Department of MIS
Chapter 6: Using Arrays.
Introduction to web development concepts
Scripting the DOM MIS 3502, Fall 2016 Jeremy Shafer Department of MIS
Microsoft Visual Basic 2005: Reloaded Second Edition
Class01 Course Introduction
PHP Arrays Functions.
Foundations of Programming: Arrays
PHP: includes MIS 3501 Jeremy Shafer Department of MIS
Class07 PHP: loops and includes
PDO Database Connections: Getting data out of the database
>> JavaScript: Arrays
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Arrays MIS 3502 Jeremy Shafer Department of MIS Fox School of Business
Repeating Instructions And Advance collection
PDO Database Connections: Getting data out of the database
Form Data (part 2) MIS 3501 Jeremy Shafer Department of MIS
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
A (gentle???) Introduction to JavaScript
Creation, Traversal, Insertion and Removal
Form Data (part 2) MIS 3501 Jeremy Shafer Department of MIS
Class07 PHP: loops MIS 3501 Jeremy Shafer Department of MIS
STL - Algorithms.
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
JavaScript Arrays.
Multidimensional Arrays
Chapter 7 Part 2 Edited by JJ Shepherd
Class05 How to get data from a form
MySQL Backup, Transfer and Restore
MSIS 655 Advanced Business Applications Programming
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
PDO Revisited MIS 3502 Jeremy Shafer Department of MIS
Sessions and cookies MIS 3501 Jeremy Shafer Department of MIS
An Introduction to Animation
MIS JavaScript and API Workshop (Part 2)
Multidimensional array
Aaa, bbb, ccc, ddd..
Programming Control Structures with JavaScript Part 2
Getting started with jQuery
An introduction to jQuery
Arrays Part 2.
Loops and Arrays in JavaScript
PDO and Arrays MIS 3502 Jeremy Shafer Department of MIS
Linear Algebra review (optional)
Programming Control Structures with JavaScript
PHP Array.
Ps Module 7 – Part II 2D Arrays and LISTS 8/29/2019 CSE 1321 Module 7.
Presentation transcript:

Class06 Arrays MIS 3502 Jeremy Shafer Department of MIS Fox School of Business Temple University

Getting Started It’s time for a gentle (re)introduction to arrays. Our objectives Know what an array is. Be able to create an array in PHP (if you need to) and other array basics Types of arrays Associative vs. Numerically Indexed Arrays One dimensional vs. Multi-dimensional Rectangular vs. Jagged How to loop through arrays Debugging tip – use print_r(); Options for the fetchAll method Sorting Arrays

What is an array? An array is a data type that can contain one or more items called elements. Each element stores a value that you can refer to with an index. The length of the array indicates the number of elements that it contains. In short, an array is a structure that allows us to store multiple pieces of similar data.

Creating an array

Arrays can store any data type. Notice that we are using numbers to index our array here. We’d call that a numerically indexed array!

Appending an element to an Array This is still a numerically indexed array! What is the value of $letters[2] ???

Manipulating array contents How to set a value at a specific index $letters = array('a', 'b', 'c', 'd'); // a, b, c, d $letters[0] = 'e'; // e, b, c, d $letters[3] = 'f'; // e, b, c, f How to get values from an array $letters = array('a', 'b', 'c', 'd'); // a, b, c, d $letter1 = $letters[0]; // $letter1 is 'a' $letter2 = $letters[1]; // $letter2 is 'b'

Another option…

Instead of: array(value1,valule2,value3, …) Associative Arrays Instead of: array(value1,valule2,value3, …) You can see that the differences in syntax between working with associative arrays, and a numerically indexed arrays are pretty minor.

More options…

One Dimensional Array

Multidimensional Arrays

Multidimensional Arrays

Using a “for” loop The PHP function count() will return the number of elements in an array. That can be handy for controlling a “for” loop like this one.

Using a “foreach” loop.

A handy function… Let’s try that…

Sorting an array Let’s try this too. What happens when sort() encounters a multidimensional array?

Where do arrays come from?

Some fetchAll options PDO::FETCH_BOTH (default): returns an array indexed by both column name and 0-indexed column number as returned in your result set PDO::FETCH_ASSOC: returns an array indexed by column name as returned in your result set PDO::FETCH_NUM: returns an array indexed by column number as returned in your result set, starting at column 0 And.. there are others. But these three you should know. If you want to know more: http://php.net/manual/en/pdostatement.fetch.php

Ok… let’s try a challenge