SlideShare a Scribd company logo
PHP Day 3  Geshan Manandhar Developer,  Young Innovations Pvt. Limited www.geshanmanandhar.com http://www.php.net
PHP Strings A string is series of characters.  In PHP, a character is the same as a byte, which is exactly 256 different characters possible. <?php $s=“I am a string”; $s2=‘I am also a string”; print $s.”---”.$s2; ?>
PHP Strings Another Example <?php $beer = 'Heineken'; echo &quot;<br>$beer's taste is great.&quot;;  // works, &quot;'&quot; is an invalid character for varnames echo &quot;<br>He drank some $beers.&quot;;  // won't work, 's' is a valid character for varnames echo &quot;<br>He drank some ${beer}s.&quot;; // works echo &quot;<br>He drank some {$beer}s.&quot;; // works ?>
Important String Functions explode  (string $delimiter, string $string) nl2br  ( string $string ) strcmp  ( string $str1, string $str2 ) strlen  ( string $string ) strtolower  ( string $str ) substr  ( string $string, int $start [, int $length] ) trim  ( string $str ) Example code at  day03\prog22_string_functions.php
Array In computer science an array is a data structure consisting of a group of elements that are accessed by indexing.  In most programming languages each element has the same data type and the array occupies a contiguous area of storage.  Most programming languages have a built-in array data type.
Array ?php $fruits_1 = array (&quot;Apple&quot;, &quot;Mango&quot;, &quot;Banana&quot;); $fruits_2 = array ( 0 => &quot;Appple&quot;, 1 => &quot;Mango&quot;, 2 => &quot;Banana&quot; ); $fruits_3[] = &quot;Apple&quot;; $fruits_3[] = &quot;Mango&quot;; $fruits_3[] = &quot;Banana&quot;; ?> //Program code: day03\prog23_array_more.php
Multi-Dimensional Array <?php $shop = array( array( Title => &quot;rose&quot;,    Price => 1.25,     Number => 15      ),     array( Title => &quot;daisy&quot;,    Price => 0.75,   Number => 25,     ),   array( Title => &quot;orchid&quot;,      Price => 1.15,     Number => 7    )   ); ?> //full code at day03\prog24_array_multi.php
Important Array Function: asort asort($array) – Sort an array and maintain index association  <?php $fruits = array (&quot;d&quot; => &quot;lemon&quot;, &quot;a&quot; => &quot;orange&quot;, &quot;b&quot; => &quot;banana&quot;, &quot;c&quot; => &quot;apple&quot;); asort($fruits); foreach ($fruits as $key => $val) { echo &quot;$key = $val\n&quot;; } ?>
Important Array Function: push/pop array_push($array, element1,…) <?php $stack = array(&quot;orange&quot;, &quot;banana&quot;); array_push($stack, &quot;apple&quot;, &quot;raspberry&quot;); print_r($stack); ?> array_pop($array) <?php $stack = array(&quot;orange&quot;, &quot;banana&quot;, &quot;apple&quot;, &quot;raspberry&quot;); $fruit = array_pop($stack); print_r($stack); ?>
Important Array Function: search array_search($array, “item1”, “item2”…); <?php $array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red'); $key = array_search('green', $array); // $key = 2; $key = array_search('red', $array);   // $key = 1; ?>
Important Array Function : rand array_random ($array, no_of_entries); <?php $sentence = &quot;Pick one or more random entries out of an array&quot;; $input = explode(&quot; &quot;,$sentence); $rand_keys = array_rand($input, 2); echo $input[$rand_keys[0]] . &quot;\n&quot;; echo &quot;<br>&quot;; echo $input[$rand_keys[1]] . &quot;\n&quot;; ?>
Important Array Function : reverse array_reverse($array) <?php $input  = array(&quot;php&quot;, 4.0, &quot;green&quot;, &quot;red&quot;); $result = array_reverse($input); $result_keyed = array_reverse($input, true); ?>
Important Array Function : merge array_merge($array1, $array2…); <?php $array1 = array(&quot;color&quot; => &quot;red&quot;, 2, 4); $array2 = array(&quot;a&quot;, &quot;b&quot;, &quot;color&quot; => &quot;green&quot;, &quot;shape&quot; => &quot;trapezoid&quot;, 4); $result = array_merge($array1, $array2); print_r($result); ?>
Important Array Function: keys array_keys($array, param) <?php $array = array(0 => 100, &quot;color&quot; => &quot;red&quot;); print_r(array_keys($array)); $array = array(&quot;blue&quot;, &quot;red&quot;, &quot;green&quot;, &quot;blue&quot;, &quot;blue&quot;); print_r(array_keys($array, &quot;blue&quot;)); ?>
Date in php Code   Description d   Day of the month with leading zeros D  Day of the week as a three-letter abbreviation F  Name of the month h  Hour from 01to 12 H  Hour from 00 to 23 g  Hour from  1 to 12(no leading zeroes) G  Hour from 0 to 23(no leading zeroes) i  Minutes j  Day of the month with no leading zeroes l  Day of the week m  Month number from 01 to 12 M  Abbreviated month name (Jan, Feb…) n  Month number from 1 to 23(no leading zeroes) s  Seconds 00 to 59 S  Ordinal suffix for day of the month (1st, 2nd, 3rd) y  Year as two digits Y  Year as four digits z  Day of the year from 0 to 365
Some Date examples <?php // Assuming today is: March 10th, 2008, 5:16:18 pm $today = date(&quot;F j, Y, g:i a&quot;); // March 10, 2008, 5:16 pm $today = date(&quot;m.d.y&quot;); // 03.10.08 $today = date(&quot;j, n, Y&quot;); // 10, 3, 2008 $today = date(&quot;Ymd&quot;);  // 20080310 $today = date('h-i-s, j-m-y, it is w Day z ');  $today = date('\i\t \i\s \t\h\e jS \d\a\y.');   // It is the 10th day. $today = date(&quot;D M j G:i:s T Y&quot;); $today = date('H:m:s \m \i\s\ \m\o\n\t\h');  $today = date(&quot;H:i:s&quot;); // 17:16:17 ?>
Important Debugging Functions print_r Prints human-readable information about a variable  var_dump Dumps information about a variable  die() or exit() Dumps information about a variable
The more you dig in the more you find out Find out other built in functions in PHP yourself. Search at  www.php.net  for more.
Questions Put forward your queries.
Lets get rolling Print today’s date like Today is: December 18, 2008 and time is 12:10:10 PM. Reverse this sentence $str= “PHP learn to want I “ into a meaningful sentence, with use of array_reverse. “ Learning PHP is not that easy and not that difficult” – print it in lower and upper case with its string length.

More Related Content

What's hot (18)

PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
Henry Osborne
 
Chap 3php array part1
Chap 3php array part1Chap 3php array part1
Chap 3php array part1
monikadeshmane
 
PHP array 1
PHP array 1PHP array 1
PHP array 1
Mudasir Syed
 
PHP Unit 4 arrays
PHP Unit 4 arraysPHP Unit 4 arrays
PHP Unit 4 arrays
Kumar
 
Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
Vineet Kumar Saini
 
Perl
PerlPerl
Perl
RaviShankar695257
 
Lists and arrays
Lists and arraysLists and arrays
Lists and arrays
Krasimir Berov (Красимир Беров)
 
DBIx::Class introduction - 2010
DBIx::Class introduction - 2010DBIx::Class introduction - 2010
DBIx::Class introduction - 2010
leo lapworth
 
Marcs (bio)perl course
Marcs (bio)perl courseMarcs (bio)perl course
Marcs (bio)perl course
BITS
 
DBIx::Class beginners
DBIx::Class beginnersDBIx::Class beginners
DBIx::Class beginners
leo lapworth
 
Working with text, Regular expressions
Working with text, Regular expressionsWorking with text, Regular expressions
Working with text, Regular expressions
Krasimir Berov (Красимир Беров)
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
Dave Cross
 
Scripting3
Scripting3Scripting3
Scripting3
Nao Dara
 
Intermediate Perl
Intermediate PerlIntermediate Perl
Intermediate Perl
Dave Cross
 
Climbing the Abstract Syntax Tree (php[world] 2019)
Climbing the Abstract Syntax Tree (php[world] 2019)Climbing the Abstract Syntax Tree (php[world] 2019)
Climbing the Abstract Syntax Tree (php[world] 2019)
James Titcumb
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
Dave Cross
 
Introduction to Perl Best Practices
Introduction to Perl Best PracticesIntroduction to Perl Best Practices
Introduction to Perl Best Practices
José Castro
 
Hashes
HashesHashes
Hashes
Krasimir Berov (Красимир Беров)
 

Viewers also liked (6)

PHP Basic & Arrays
PHP Basic & ArraysPHP Basic & Arrays
PHP Basic & Arrays
M.Zalmai Rahmani
 
Php
PhpPhp
Php
Ajaigururaj R
 
Array in php
Array in phpArray in php
Array in php
Ashok Kumar
 
My self learn -Php
My self learn -PhpMy self learn -Php
My self learn -Php
laavanyaD2009
 
Web app development_php_06
Web app development_php_06Web app development_php_06
Web app development_php_06
Hassen Poreya
 
Php string function
Php string function Php string function
Php string function
Ravi Bhadauria
 
Ad

Similar to 03 Php Array String Functions (20)

Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128
PrinceGuru MS
 
Intoduction to php arrays
Intoduction to php arraysIntoduction to php arrays
Intoduction to php arrays
baabtra.com - No. 1 supplier of quality freshers
 
Php functions
Php functionsPhp functions
Php functions
JIGAR MAKHIJA
 
PHP tips and tricks
PHP tips and tricks PHP tips and tricks
PHP tips and tricks
Damien Seguy
 
Php2
Php2Php2
Php2
Keennary Pungyera
 
UNIT IV (4).pptx
UNIT IV (4).pptxUNIT IV (4).pptx
UNIT IV (4).pptx
DrDhivyaaCRAssistant
 
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Dhivyaa C.R
 
Variables In Php 1
Variables In Php 1Variables In Php 1
Variables In Php 1
Digital Insights - Digital Marketing Agency
 
Arrays in php
Arrays in phpArrays in php
Arrays in php
Laiby Thomas
 
PHP-04-Arrays.ppt
PHP-04-Arrays.pptPHP-04-Arrays.ppt
PHP-04-Arrays.ppt
Leandro660423
 
Php Learning show
Php Learning showPhp Learning show
Php Learning show
Gnugroup India
 
PHP and MySQL with snapshots
 PHP and MySQL with snapshots PHP and MySQL with snapshots
PHP and MySQL with snapshots
richambra
 
P H P Part I, By Kian
P H P  Part  I,  By  KianP H P  Part  I,  By  Kian
P H P Part I, By Kian
phelios
 
Chapter 2 wbp.pptx
Chapter 2 wbp.pptxChapter 2 wbp.pptx
Chapter 2 wbp.pptx
40NehaPagariya
 
lab4_php
lab4_phplab4_php
lab4_php
tutorialsruby
 
lab4_php
lab4_phplab4_php
lab4_php
tutorialsruby
 
How to run PHP code in XAMPP.docx (1).pdf
How to run PHP code in XAMPP.docx (1).pdfHow to run PHP code in XAMPP.docx (1).pdf
How to run PHP code in XAMPP.docx (1).pdf
rajeswaria21
 
DIWE - Advanced PHP Concepts
DIWE - Advanced PHP ConceptsDIWE - Advanced PHP Concepts
DIWE - Advanced PHP Concepts
Rasan Samarasinghe
 
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
SchoolEducationDepar
 
Ad

More from Geshan Manandhar (20)

How to build an image to geo location guesser using Gemini 2 - Canberra.pdf
How to build an image to geo location guesser using Gemini 2 - Canberra.pdfHow to build an image to geo location guesser using Gemini 2 - Canberra.pdf
How to build an image to geo location guesser using Gemini 2 - Canberra.pdf
Geshan Manandhar
 
build-with-ai-sydney AI for web devs Tamas Piros
build-with-ai-sydney AI for web devs Tamas Pirosbuild-with-ai-sydney AI for web devs Tamas Piros
build-with-ai-sydney AI for web devs Tamas Piros
Geshan Manandhar
 
Are logs a software engineer’s best friend? Yes -- follow these best practices
Are logs a software engineer’s best friend? Yes -- follow these best practicesAre logs a software engineer’s best friend? Yes -- follow these best practices
Are logs a software engineer’s best friend? Yes -- follow these best practices
Geshan Manandhar
 
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
Geshan Manandhar
 
Moving from A and B to 150 microservices, the journey, and learnings
Moving from A and B to 150 microservices, the journey, and learningsMoving from A and B to 150 microservices, the journey, and learnings
Moving from A and B to 150 microservices, the journey, and learnings
Geshan Manandhar
 
Adopt a painless continuous delivery culture, add more business value
Adopt a painless continuous delivery culture, add more business valueAdopt a painless continuous delivery culture, add more business value
Adopt a painless continuous delivery culture, add more business value
Geshan Manandhar
 
Things i wished i knew as a junior developer
Things i wished i knew as a junior developerThings i wished i knew as a junior developer
Things i wished i knew as a junior developer
Geshan Manandhar
 
Embrace chatops, stop installing deployment software - Laracon EU 2016
Embrace chatops, stop installing deployment software - Laracon EU 2016Embrace chatops, stop installing deployment software - Laracon EU 2016
Embrace chatops, stop installing deployment software - Laracon EU 2016
Geshan Manandhar
 
Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...
Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...
Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...
Geshan Manandhar
 
Embrace chatOps, stop installing deployment software
Embrace chatOps, stop installing deployment softwareEmbrace chatOps, stop installing deployment software
Embrace chatOps, stop installing deployment software
Geshan Manandhar
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable code
Geshan Manandhar
 
Software engineering In Nepal mid 2015 part 01
Software engineering In Nepal mid 2015 part 01Software engineering In Nepal mid 2015 part 01
Software engineering In Nepal mid 2015 part 01
Geshan Manandhar
 
A simplified Gitflow
A simplified GitflowA simplified Gitflow
A simplified Gitflow
Geshan Manandhar
 
How to become a better software company technically
How to become a better software company technicallyHow to become a better software company technically
How to become a better software company technically
Geshan Manandhar
 
Things I wished I knew while doing my tech bachelor / undergraduate
Things I wished I knew while doing my tech bachelor / undergraduateThings I wished I knew while doing my tech bachelor / undergraduate
Things I wished I knew while doing my tech bachelor / undergraduate
Geshan Manandhar
 
Message Queues a basic overview
Message Queues a basic overviewMessage Queues a basic overview
Message Queues a basic overview
Geshan Manandhar
 
Most popular brands, people on facebook in nepal as of 2013 q4
Most popular brands, people on facebook in nepal as of 2013 q4Most popular brands, people on facebook in nepal as of 2013 q4
Most popular brands, people on facebook in nepal as of 2013 q4
Geshan Manandhar
 
Drupal 7 basic setup and contrib modules for a brochure website
Drupal 7 basic setup and contrib modules for a brochure websiteDrupal 7 basic setup and contrib modules for a brochure website
Drupal 7 basic setup and contrib modules for a brochure website
Geshan Manandhar
 
Git intro hands on windows with msysgit
Git intro hands on windows with msysgitGit intro hands on windows with msysgit
Git intro hands on windows with msysgit
Geshan Manandhar
 
Drupal 7 install with modules and themes
Drupal 7 install with modules and themesDrupal 7 install with modules and themes
Drupal 7 install with modules and themes
Geshan Manandhar
 
How to build an image to geo location guesser using Gemini 2 - Canberra.pdf
How to build an image to geo location guesser using Gemini 2 - Canberra.pdfHow to build an image to geo location guesser using Gemini 2 - Canberra.pdf
How to build an image to geo location guesser using Gemini 2 - Canberra.pdf
Geshan Manandhar
 
build-with-ai-sydney AI for web devs Tamas Piros
build-with-ai-sydney AI for web devs Tamas Pirosbuild-with-ai-sydney AI for web devs Tamas Piros
build-with-ai-sydney AI for web devs Tamas Piros
Geshan Manandhar
 
Are logs a software engineer’s best friend? Yes -- follow these best practices
Are logs a software engineer’s best friend? Yes -- follow these best practicesAre logs a software engineer’s best friend? Yes -- follow these best practices
Are logs a software engineer’s best friend? Yes -- follow these best practices
Geshan Manandhar
 
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
Geshan Manandhar
 
Moving from A and B to 150 microservices, the journey, and learnings
Moving from A and B to 150 microservices, the journey, and learningsMoving from A and B to 150 microservices, the journey, and learnings
Moving from A and B to 150 microservices, the journey, and learnings
Geshan Manandhar
 
Adopt a painless continuous delivery culture, add more business value
Adopt a painless continuous delivery culture, add more business valueAdopt a painless continuous delivery culture, add more business value
Adopt a painless continuous delivery culture, add more business value
Geshan Manandhar
 
Things i wished i knew as a junior developer
Things i wished i knew as a junior developerThings i wished i knew as a junior developer
Things i wished i knew as a junior developer
Geshan Manandhar
 
Embrace chatops, stop installing deployment software - Laracon EU 2016
Embrace chatops, stop installing deployment software - Laracon EU 2016Embrace chatops, stop installing deployment software - Laracon EU 2016
Embrace chatops, stop installing deployment software - Laracon EU 2016
Geshan Manandhar
 
Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...
Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...
Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...
Geshan Manandhar
 
Embrace chatOps, stop installing deployment software
Embrace chatOps, stop installing deployment softwareEmbrace chatOps, stop installing deployment software
Embrace chatOps, stop installing deployment software
Geshan Manandhar
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable code
Geshan Manandhar
 
Software engineering In Nepal mid 2015 part 01
Software engineering In Nepal mid 2015 part 01Software engineering In Nepal mid 2015 part 01
Software engineering In Nepal mid 2015 part 01
Geshan Manandhar
 
How to become a better software company technically
How to become a better software company technicallyHow to become a better software company technically
How to become a better software company technically
Geshan Manandhar
 
Things I wished I knew while doing my tech bachelor / undergraduate
Things I wished I knew while doing my tech bachelor / undergraduateThings I wished I knew while doing my tech bachelor / undergraduate
Things I wished I knew while doing my tech bachelor / undergraduate
Geshan Manandhar
 
Message Queues a basic overview
Message Queues a basic overviewMessage Queues a basic overview
Message Queues a basic overview
Geshan Manandhar
 
Most popular brands, people on facebook in nepal as of 2013 q4
Most popular brands, people on facebook in nepal as of 2013 q4Most popular brands, people on facebook in nepal as of 2013 q4
Most popular brands, people on facebook in nepal as of 2013 q4
Geshan Manandhar
 
Drupal 7 basic setup and contrib modules for a brochure website
Drupal 7 basic setup and contrib modules for a brochure websiteDrupal 7 basic setup and contrib modules for a brochure website
Drupal 7 basic setup and contrib modules for a brochure website
Geshan Manandhar
 
Git intro hands on windows with msysgit
Git intro hands on windows with msysgitGit intro hands on windows with msysgit
Git intro hands on windows with msysgit
Geshan Manandhar
 
Drupal 7 install with modules and themes
Drupal 7 install with modules and themesDrupal 7 install with modules and themes
Drupal 7 install with modules and themes
Geshan Manandhar
 

Recently uploaded (20)

Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FMESupporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptxFIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API CatalogMuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptxFIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FMESupporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptxFIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API CatalogMuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptxFIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 

03 Php Array String Functions

  • 1. PHP Day 3 Geshan Manandhar Developer, Young Innovations Pvt. Limited www.geshanmanandhar.com http://www.php.net
  • 2. PHP Strings A string is series of characters. In PHP, a character is the same as a byte, which is exactly 256 different characters possible. <?php $s=“I am a string”; $s2=‘I am also a string”; print $s.”---”.$s2; ?>
  • 3. PHP Strings Another Example <?php $beer = 'Heineken'; echo &quot;<br>$beer's taste is great.&quot;; // works, &quot;'&quot; is an invalid character for varnames echo &quot;<br>He drank some $beers.&quot;; // won't work, 's' is a valid character for varnames echo &quot;<br>He drank some ${beer}s.&quot;; // works echo &quot;<br>He drank some {$beer}s.&quot;; // works ?>
  • 4. Important String Functions explode (string $delimiter, string $string) nl2br ( string $string ) strcmp ( string $str1, string $str2 ) strlen ( string $string ) strtolower ( string $str ) substr ( string $string, int $start [, int $length] ) trim ( string $str ) Example code at day03\prog22_string_functions.php
  • 5. Array In computer science an array is a data structure consisting of a group of elements that are accessed by indexing. In most programming languages each element has the same data type and the array occupies a contiguous area of storage. Most programming languages have a built-in array data type.
  • 6. Array ?php $fruits_1 = array (&quot;Apple&quot;, &quot;Mango&quot;, &quot;Banana&quot;); $fruits_2 = array ( 0 => &quot;Appple&quot;, 1 => &quot;Mango&quot;, 2 => &quot;Banana&quot; ); $fruits_3[] = &quot;Apple&quot;; $fruits_3[] = &quot;Mango&quot;; $fruits_3[] = &quot;Banana&quot;; ?> //Program code: day03\prog23_array_more.php
  • 7. Multi-Dimensional Array <?php $shop = array( array( Title => &quot;rose&quot;, Price => 1.25, Number => 15 ), array( Title => &quot;daisy&quot;, Price => 0.75, Number => 25, ), array( Title => &quot;orchid&quot;, Price => 1.15, Number => 7 ) ); ?> //full code at day03\prog24_array_multi.php
  • 8. Important Array Function: asort asort($array) – Sort an array and maintain index association <?php $fruits = array (&quot;d&quot; => &quot;lemon&quot;, &quot;a&quot; => &quot;orange&quot;, &quot;b&quot; => &quot;banana&quot;, &quot;c&quot; => &quot;apple&quot;); asort($fruits); foreach ($fruits as $key => $val) { echo &quot;$key = $val\n&quot;; } ?>
  • 9. Important Array Function: push/pop array_push($array, element1,…) <?php $stack = array(&quot;orange&quot;, &quot;banana&quot;); array_push($stack, &quot;apple&quot;, &quot;raspberry&quot;); print_r($stack); ?> array_pop($array) <?php $stack = array(&quot;orange&quot;, &quot;banana&quot;, &quot;apple&quot;, &quot;raspberry&quot;); $fruit = array_pop($stack); print_r($stack); ?>
  • 10. Important Array Function: search array_search($array, “item1”, “item2”…); <?php $array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red'); $key = array_search('green', $array); // $key = 2; $key = array_search('red', $array);   // $key = 1; ?>
  • 11. Important Array Function : rand array_random ($array, no_of_entries); <?php $sentence = &quot;Pick one or more random entries out of an array&quot;; $input = explode(&quot; &quot;,$sentence); $rand_keys = array_rand($input, 2); echo $input[$rand_keys[0]] . &quot;\n&quot;; echo &quot;<br>&quot;; echo $input[$rand_keys[1]] . &quot;\n&quot;; ?>
  • 12. Important Array Function : reverse array_reverse($array) <?php $input = array(&quot;php&quot;, 4.0, &quot;green&quot;, &quot;red&quot;); $result = array_reverse($input); $result_keyed = array_reverse($input, true); ?>
  • 13. Important Array Function : merge array_merge($array1, $array2…); <?php $array1 = array(&quot;color&quot; => &quot;red&quot;, 2, 4); $array2 = array(&quot;a&quot;, &quot;b&quot;, &quot;color&quot; => &quot;green&quot;, &quot;shape&quot; => &quot;trapezoid&quot;, 4); $result = array_merge($array1, $array2); print_r($result); ?>
  • 14. Important Array Function: keys array_keys($array, param) <?php $array = array(0 => 100, &quot;color&quot; => &quot;red&quot;); print_r(array_keys($array)); $array = array(&quot;blue&quot;, &quot;red&quot;, &quot;green&quot;, &quot;blue&quot;, &quot;blue&quot;); print_r(array_keys($array, &quot;blue&quot;)); ?>
  • 15. Date in php Code Description d Day of the month with leading zeros D Day of the week as a three-letter abbreviation F Name of the month h Hour from 01to 12 H Hour from 00 to 23 g Hour from 1 to 12(no leading zeroes) G Hour from 0 to 23(no leading zeroes) i Minutes j Day of the month with no leading zeroes l Day of the week m Month number from 01 to 12 M Abbreviated month name (Jan, Feb…) n Month number from 1 to 23(no leading zeroes) s Seconds 00 to 59 S Ordinal suffix for day of the month (1st, 2nd, 3rd) y Year as two digits Y Year as four digits z Day of the year from 0 to 365
  • 16. Some Date examples <?php // Assuming today is: March 10th, 2008, 5:16:18 pm $today = date(&quot;F j, Y, g:i a&quot;); // March 10, 2008, 5:16 pm $today = date(&quot;m.d.y&quot;); // 03.10.08 $today = date(&quot;j, n, Y&quot;); // 10, 3, 2008 $today = date(&quot;Ymd&quot;);  // 20080310 $today = date('h-i-s, j-m-y, it is w Day z ');  $today = date('\i\t \i\s \t\h\e jS \d\a\y.');   // It is the 10th day. $today = date(&quot;D M j G:i:s T Y&quot;); $today = date('H:m:s \m \i\s\ \m\o\n\t\h'); $today = date(&quot;H:i:s&quot;); // 17:16:17 ?>
  • 17. Important Debugging Functions print_r Prints human-readable information about a variable var_dump Dumps information about a variable die() or exit() Dumps information about a variable
  • 18. The more you dig in the more you find out Find out other built in functions in PHP yourself. Search at www.php.net for more.
  • 19. Questions Put forward your queries.
  • 20. Lets get rolling Print today’s date like Today is: December 18, 2008 and time is 12:10:10 PM. Reverse this sentence $str= “PHP learn to want I “ into a meaningful sentence, with use of array_reverse. “ Learning PHP is not that easy and not that difficult” – print it in lower and upper case with its string length.