×
1 Choose EITC/EITCA Certificates
2 Learn and take online exams
3 Get your IT skills certified

Confirm your IT skills and competencies under the European IT Certification framework from anywhere in the world fully online.

EITCA Academy

Digital skills attestation standard by the European IT Certification Institute aiming to support Digital Society development

LOG IN TO YOUR ACCOUNT

CREATE AN ACCOUNT FORGOT YOUR PASSWORD?

FORGOT YOUR PASSWORD?

AAH, WAIT, I REMEMBER NOW!

CREATE AN ACCOUNT

ALREADY HAVE AN ACCOUNT?
EUROPEAN INFORMATION TECHNOLOGIES CERTIFICATION ACADEMY - ATTESTING YOUR PROFESSIONAL DIGITAL SKILLS
  • SIGN UP
  • LOGIN
  • INFO

EITCA Academy

EITCA Academy

The European Information Technologies Certification Institute - EITCI ASBL

Certification Provider

EITCI Institute ASBL

Brussels, European Union

Governing European IT Certification (EITC) framework in support of the IT professionalism and Digital Society

  • CERTIFICATES
    • EITCA ACADEMIES
      • EITCA ACADEMIES CATALOGUE<
      • EITCA/CG COMPUTER GRAPHICS
      • EITCA/IS INFORMATION SECURITY
      • EITCA/BI BUSINESS INFORMATION
      • EITCA/KC KEY COMPETENCIES
      • EITCA/EG E-GOVERNMENT
      • EITCA/WD WEB DEVELOPMENT
      • EITCA/AI ARTIFICIAL INTELLIGENCE
    • EITC CERTIFICATES
      • EITC CERTIFICATES CATALOGUE<
      • COMPUTER GRAPHICS CERTIFICATES
      • WEB DESIGN CERTIFICATES
      • 3D DESIGN CERTIFICATES
      • OFFICE IT CERTIFICATES
      • BITCOIN BLOCKCHAIN CERTIFICATE
      • WORDPRESS CERTIFICATE
      • CLOUD PLATFORM CERTIFICATENEW
    • EITC CERTIFICATES
      • INTERNET CERTIFICATES
      • CRYPTOGRAPHY CERTIFICATES
      • BUSINESS IT CERTIFICATES
      • TELEWORK CERTIFICATES
      • PROGRAMMING CERTIFICATES
      • DIGITAL PORTRAIT CERTIFICATE
      • WEB DEVELOPMENT CERTIFICATES
      • DEEP LEARNING CERTIFICATESNEW
    • CERTIFICATES FOR
      • EU PUBLIC ADMINISTRATION
      • TEACHERS AND EDUCATORS
      • IT SECURITY PROFESSIONALS
      • GRAPHICS DESIGNERS & ARTISTS
      • BUSINESSMEN AND MANAGERS
      • BLOCKCHAIN DEVELOPERS
      • WEB DEVELOPERS
      • CLOUD AI EXPERTSNEW
  • FEATURED
  • SUBSIDY
  • HOW IT WORKS
  •   IT ID
  • ABOUT
  • CONTACT
  • MY ORDER
    Your current order is empty.
EITCIINSTITUTE
CERTIFIED

What are the two ways to create an indexed array in PHP?

by EITCA Academy / Tuesday, 08 August 2023 / Published in Web Development, EITC/WD/PMSF PHP and MySQL Fundamentals, PHP data structures, Arrays, Examination review

Creating an indexed array in PHP can be accomplished in two ways: by using the array() function or by using square brackets []. These methods allow developers to store and access multiple values under a single variable, making it easier to manage and manipulate data.

The first method involves using the array() function, which is a built-in function in PHP. This function takes any number of comma-separated values and returns an array containing those values. To create an indexed array using this method, we simply assign the returned array to a variable. Here is an example:

php
$fruits = array("apple", "banana", "orange");

In this example, the variable `$fruits` is assigned an indexed array containing three elements: "apple", "banana", and "orange". Each element is assigned a numerical index starting from 0. Therefore, "apple" has an index of 0, "banana" has an index of 1, and "orange" has an index of 2.

The second method involves using square brackets [] to directly assign values to an array. This method is more concise and often preferred by developers. Here is an example:

php
$fruits = ["apple", "banana", "orange"];

This code snippet achieves the same result as the previous example. The variable `$fruits` is assigned an indexed array with the same elements and indices.

Both methods allow for easy access and manipulation of array elements. To access a specific element, we can use its index within square brackets. For example:

php
echo $fruits[1]; // Output: banana

In this example, we are accessing the element at index 1 of the `$fruits` array, which is "banana". The value is then echoed to the screen.

It is important to note that indices in PHP arrays are automatically assigned if not explicitly specified. The first element is assigned an index of 0, the second element has an index of 1, and so on. However, if we explicitly assign indices to elements, PHP will use those indices instead. Here is an example:

php
$fruits = [0 => "apple", 2 => "banana", 5 => "orange"];

In this case, we have specified the indices for each element. The first element "apple" has an index of 0, the second element "banana" has an index of 2, and the third element "orange" has an index of 5.

There are two ways to create an indexed array in PHP: using the array() function and using square brackets []. Both methods allow developers to store and access multiple values under a single variable. The array() function takes comma-separated values and returns an array, while square brackets [] provide a more concise way to directly assign values to an array. Both methods support easy access and manipulation of array elements using numerical indices.

Other recent questions and answers regarding Arrays:

  • How do we access elements in an associative array?
  • How can we add a new element to the end of an indexed array?
  • How do we access a specific value in an indexed array?
  • What are the three types of arrays in PHP?

More questions and answers:

  • Field: Web Development
  • Programme: EITC/WD/PMSF PHP and MySQL Fundamentals (go to the certification programme)
  • Lesson: PHP data structures (go to related lesson)
  • Topic: Arrays (go to related topic)
  • Examination review
Tagged under: Array Creation, Arrays, Indexed Arrays, PHP, PHP Data Structures, Web Development
Home » Arrays / EITC/WD/PMSF PHP and MySQL Fundamentals / Examination review / PHP data structures / Web Development » What are the two ways to create an indexed array in PHP?

Certification Center

USER MENU

  • My Account

CERTIFICATE CATEGORY

  • EITC Certification (105)
  • EITCA Certification (9)

What are you looking for?

  • Introduction
  • How it works?
  • EITCA Academies
  • EITCI DSJC Subsidy
  • Full EITC catalogue
  • Your order
  • Featured
  •   IT ID
  • EITCA reviews (Medium publ.)
  • About
  • Contact

EITCA Academy is a part of the European IT Certification framework

The European IT Certification framework has been established in 2008 as a Europe based and vendor independent standard in widely accessible online certification of digital skills and competencies in many areas of professional digital specializations. The EITC framework is governed by the European IT Certification Institute (EITCI), a non-profit certification authority supporting information society growth and bridging the digital skills gap in the EU.

Eligibility for EITCA Academy 80% EITCI DSJC Subsidy support

80% of EITCA Academy fees subsidized in enrolment by

    EITCA Academy Secretary Office

    European IT Certification Institute ASBL
    Brussels, Belgium, European Union

    EITC / EITCA Certification Framework Operator
    Governing European IT Certification Standard
    Access contact form or call +32 25887351

    Follow EITCI on X
    Visit EITCA Academy on Facebook
    Engage with EITCA Academy on LinkedIn
    Check out EITCI and EITCA videos on YouTube

    Funded by the European Union

    Funded by the European Regional Development Fund (ERDF) and the European Social Fund (ESF) in series of projects since 2007, currently governed by the European IT Certification Institute (EITCI) since 2008

    Information Security Policy | DSRRM and GDPR Policy | Data Protection Policy | Record of Processing Activities | HSE Policy | Anti-Corruption Policy | Modern Slavery Policy

    Automatically translate to your language

    Terms and Conditions | Privacy Policy
    EITCA Academy
    • EITCA Academy on social media
    EITCA Academy


    © 2008-2025  European IT Certification Institute
    Brussels, Belgium, European Union

    TOP
    Chat with Support
    Chat with Support
    Questions, doubts, issues? We are here to help you!
    End chat
    Connecting...
    Do you have any questions?
    Do you have any questions?
    :
    :
    :
    Send
    Do you have any questions?
    :
    :
    Start Chat
    The chat session has ended. Thank you!
    Please rate the support you've received.
    Good Bad