What is an Array & its cases to use in PHP?

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOps School!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

arrays is a type of data structure that allows us to store multiple elements of similar data type under a single variable. the arrays are helpful to create a list of elements of similar data types, which can be accessed using their index number.

In simple words (array is a special variable, which can hold more than one value at a time).

example: assume we want to store five names and print them accordingly. this can be easily done by the use of five different string variables. but instead of five, the number rises to a hundred, then it would be really difficult for the user or developer to create so many different variables. here array comes to helps us to store every element within a single variable and also allows easy access using an index number. an array is created using with an array()function in PHP

Cases to use array in php

case1

<?php  
  $subjects=array("c++","php","java","os");  
    echo " subjects: $c++[0],$php[1],$java[2],$os[3]";  
?>  

output

subjects: c++,php,java,os

case2

<?php  
     $subjects[0]="c++";  
     $subjects[1]="php";  
      $subjects[2]="java";  
      $subjects[3]="os";  
      echo "subjects: $c++[0],$php[1],$java[2],$os[3]";  
?>  

output

subjects: c++,php,java,os

case3

<?php    
    $marks=array("c++"=>"24","php"=>"56","java"=>"77");    
   echo "c++: ".$marks["c++"]."<br/>";  
    echo "php: ".$marks["phpjava"]."<br/>";  
    echo "java: ".$marks["Kartik"]."<br/>";  
?>    

output

c++:24
php:56
java:77

case4

<?php    
    $marks["c++"]="24";    
    $marks["php"]="56";    
    $marks["java"]="77";    
   echo "c++  ".$marks["c++"]."<br/>";  
   echo "php  ".$marks["php"]."<br/>";  
   echo "java  ".$marks["java"]."<br/>";  
?>   

output

c++  24
php  56
java  77

Related Posts

PR Points Calculator : The Ultimate Guide to Immigration Eligibility Around the World

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

The Complete Guide to Certified FinOps Professional: Career Path, ROI, and Technical Mastery

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

Certified FinOps Manager: The Complete Guide to Mastering Cloud Value and Career Growth

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

Certified FinOps Engineer Career Path for Engineers and Managers

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

Certified FinOps Architect: Strategic Cloud Optimization and Financial Governance

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More

Mastering Data Pipelines: The Complete Career Guide to CDOM – Certified DataOps Manager

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps! We spend hours scrolling social media and waste money on things we forget, but won’t spend 30…

Read More
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x