How to declare an array in php?

Eg :

var $arr = array('apple', 'grape', 'lemon');

Just like that, except you don’t need the var.

Try the PHP site and this page in particular - http://php.net/manual/en/function.array.php

1 Like

PHP 5.3 and below can use the regular arrays

$array = array('Array');

While PHP 5.4 and up can use square bracket arrays since it was introduced in PHP 5.4.

$array = ['Array'];

Hey Just a single line code you require

$arrayname= array(“element1”, “element2”, “element3”);

or

$arrayname=["element1", "element2", "element3"];

in all currently supported versions of PHP and even the last copuple of now dead versions of PHP.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.