• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / PHP / PHP Numerically Indexed Array Begin With Position 0

PHP Numerically Indexed Array Begin With Position 0

August 8, 2022 Leave a Comment

In php, numerically indexed arrays begin with position 0 because php is a zero-based programming language.

$array = array(101,202,303);

print_r($array);

// Output:
Array
(
    [0] => 101
    [1] => 202
    [2] => 303
)

Depending on which programming language you use, there are sometimes different conventions and behaviors which you need to know.

One such piece of information which is valuable and important to know is which position arrays start with.

Most programming languages are zero-based and have arrays which start with the index 0.

PHP is a zero-based programming language and because of this, by default, numerically indexed arrays begin with position 0.

Below is an example showing you that numerically indexed arrays in PHP begin with position 0.

$array = array(101,202,303);

print_r($array);

// Output:
Array
(
    [0] => 101
    [1] => 202
    [2] => 303
)

Why Do Most Programming Languages Use Zero as Beginning Index of Arrays?

When you start to learn multiple programming languages, you will notice that many programming languages are zero-based. For example, PHP, Python, JavaScript, C, C++, Java are all zero-based programming languages.

Most programming languages are zero-based because it is has been argued that starting with zero makes programming much easier than if you start with 1 or any other number.

Arguably the most powerful argument on this subject comes from Edsger W. Dijkstra’s article “Why numbering should start at zero”.

Hopefully this article has been useful for you to learn that in php, numerically indexed arrays begin with position 0

Other Articles You'll Also Like:

  • 1.  Check if String Starts with Given String in php with str_starts_with()
  • 2.  Remove String from String in php with str_replace()
  • 3.  php str_replace – Replace String in php
  • 4.  Get Query String from URL in php
  • 5.  echo php – Output One or More Strings
  • 6.  php max – Find Maximum Value of Array in php
  • 7.  php str_split() – Convert String into Array of Equal Length Substrings
  • 8.  php array_slice() – Get Slice of Elements from Array
  • 9.  php array_key_exists() Function – Check if Key Exists in Array
  • 10.  Reversing an Array in php with array_reverse() Function

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy