Tags
PHP
Asked 3 years ago
13 Jul 2021
Views 199
Santiago

Santiago posted

What is a PHP array ?

What is a PHP array ?
Bonnie

Bonnie
answered Aug 22 '21 22:10

the array is a list of string or integer or float or objects which can be created in many ways in PHP
how to make an array in PHP?

1. by the array() method or construct
it only initiates the array with key and values pairs.
Array example in PHP as below


$array=array("1","2","3","4","5");

above array has string list .
array() function used to created the array in php

you can print by print_r() or var_dump() , echo will not print detailed array


print_r($array);//it will print array 




2 . by array short hand []

[code]


$array=["1","2","3","4","5"];
print_r($array); // will print array
[/code]

how to add elements to an array in PHP?


$array[]=6;

it will add new element to the array by []




how to make an empty array in PHP?


$a=array();

or

$a=[];


Post Answer