Example 1: ccreate array php
$array = array(
"foo" => "bar",
"bar" => "foo",
);
Example 2: php arrays
#Arrays
<?php
#array is a variable that holds multiple values
$people = array('Kevin', 'Jeremy ', 'Sara');
$ids = array(23, 55, 12);
$cars = ['Honda', ' Toyota', 'Ford'];
$cars[3] = ' Audi';
$cars[] = ' Chevy';
echo $people[1];
echo $ids[1];
echo $cars[1];
echo $cars[3];
echo $cars[4];
echo count($cars);
print_r($cars);
echo var_dump($cars);
$people1 = array('Kevin' => 35, 'Jeremy' => 23, 'Sara' => 19);
$ids1 = array(23 => 'Kevin', 55 => 'Jeremy', 12 => 'Sara');
echo $people1['Kevin'];
echo $ids1[23];
$people1['Jill'] = 44;
echo $people1['Jill'];
print_r($people1);
var_dump($people1);
$cars2 = array(
array('Honda',20,10),
array('Toyota',30,20),
array('Ford',23,12)
);
echo $cars2[1][0];
?>
Example 3: array php
<?php
$array = array(
"foo" => "bar",
"bar" => "foo",
);
$array = [
"foo" => "bar",
"bar" => "foo",
];
?>
Example 4: assign $variable of key value pair array to multiple variables php
$healthStructureData = [
'product' => $product,
'website_data' => $website_data,
'total_keywords' => $total_keywords,
'certificate_status' => $certificate_status,
'total_user_websites' => $total_user_websites,
];
foreach ($healthStructureData as $key => $value) {
$$key = $value;
}
Example 5: php declare array
$arr = array(
'v1',
'v2',
'v3'
);
$arr = [
'v1',
'v2',
'v3'
];
$arr = array(
'k1' => 'v1',
'k2' => 'v2',
'k3' => 'v3'
);
$arr = [
'k1' => 'v1',
'k2' => 'v2',
'k3' => 'v3'
];
Example 6: array php
<?php
$array = array(
"foo" => "bar",
"bar" => "foo",
);
$array = [
"foo" => "bar",
"bar" => "foo",
];
?>