Jump to content

PHP array() section improvement


Recommended Posts



I have been reading through the php section about arrays and even though I think it is very informative as it is, I think the section misses an example of how to assign a different variable for each of the items in the array.


I'll use the array example with the cars:


$cars = array("Volvo","BMW","Toyota");


This will yield:


Array ([0] => Volvo [1] => BMW [2] => Toyota)


Now what if the user wishes to split the array and assign a variable for each of the items in the array like for example:


Volvo = $Sweden

BMW = $Germany

Toyota = $Japan


I think an example of how this is done would be really helpful for some (including myself !).




Link to comment
Share on other sites

I'm not sure what you're asking. Making a more complicated array structure is typically application specific. You can always make an array index an array itself to create a multidimensional array, if that's what you're getting at.



$cars = array(  "volvo" => array(     "country" => "Sweden"  )); echo $cars["volvo"]["country"];
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...