How to display this using php and what type of array is this please explain
Array
(
[name] => Ajin
[username] => ajin
[password] => password
)
It's an associative array. This is how you can define it:
$array = array('name' => 'Ajin', 'username' => 'ajin', 'password' => 'password');
And you can get that output with print_r()
:
print_r($array);
It outputs:
Array
(
[name] => Ajin
[username] => ajin
[password] => password
)
You can read more about array in the manual. You can for example iterate through the array using foreach
to display it:
foreach ($array as $key => $value) {
echo $key . ': ' . $value . PHP_EOL;
}
This outputs:
name: Ajin
username: ajin
password: password
Or you can access individual values as $array['name']
:
echo $array['name'];
It's an associative array.
Associative arrays - Arrays with named keys. You can define as
$array = array(
'name' => 'Ajin',
'username' => 'ajin',
'password' => 'password'
);
And we can show the output like
print_r($array);
or you can use it as -
foreach ($array as $key => $index) {
echo " key $key => $index";
}