Member Avatar for Rahul47

What is wrong with this type of assignment ?

$name=array('ch' => 'chester' , 'mike', 'joe');

foreach( $name as $value)
{
    echo $value;
    echo "<br>";
}

Thanks.

try this

$name = array( 'ch' => 'Chester', 'mk' => 'Mike', 'jo' => 'Joe' );

There's nothing wrong with this array
The array assigns key or index ch to the chester and rest with 0,1
Here 0 is assinged to mike and 1 to joe
The chester is accessed using $name['ch'] ,mike with $name['0'] and joe with $name['1']

you can see what key is assigned to a value of array using

foreach( $name as $key => $value)
{
    echo $key;
}
Member Avatar for Rahul47

@code run: What difficulties may arise in further program if this style of assignment is used ?

Member Avatar for diafol

No problem - depends on how you want to retrieve the data.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.