Answers for "how to define array in php"

PHP
1

how to create new array in php

$array = array(
    "foo" => "bar",
    "bar" => "foo",
);
Posted by: Guest on May-10-2021
1

php declare array

// sequential array
$arr = array(
  'v1',		// $arr[0] == 'v1'
  'v2',		// $arr[1] == 'v2'
  'v3'		// $arr[2] == 'v3'
);
// or (since PHP 5.4)
$arr = [
  'v1',		// $arr[0] == 'v1'
  'v2',		// $arr[1] == 'v2'
  'v3'		// $arr[2] == 'v3'
];

// key accessed array (map like)
$arr = array(
  'k1' => 'v1',		// $arr['k1'] == 'v1'
  'k2' => 'v2',		// $arr['k2'] == 'v2'
  'k3' => 'v3'		// $arr['k3'] == 'v3'
);
// or (since PHP 5.4)
$arr = [
  'k1' => 'v1',		// $arr['k1'] == 'v1'
  'k2' => 'v2',		// $arr['k2'] == 'v2'
  'k3' => 'v3'		// $arr['k3'] == 'v3'
];
Posted by: Guest on February-17-2021
3

php array

<?php
$array = array("foo", "bar", "hello", "world");
var_dump($array);
?>
Posted by: Guest on June-17-2020
2

array in php

<?php

$cars = array("Maserati", "Porsche", "BMW");

echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";

?>
Posted by: Guest on May-23-2020
1

PHP Arrays

<?php
$cars = array("Volvo", "BMW", "Toyota");
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>
Posted by: Guest on April-02-2020
0

array php

Array
(
    [0] => Array
        (
            [name] => phone
            [price] => 700
        )

    [1] => Array
        (
            [name] => note
            [price] => 20
        )

    [2] => Array
        (
            [name] => book
            [price] => 49
        )

)
Posted by: Guest on June-28-2021

Browse Popular Code Answers by Language