Member Avatar

What is wrong with this type of assignment ?

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

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

Thanks.

Recommended Answers

try this

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

Jump to Post

All 4 Replies

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

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

Member Avatar

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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.