Jump to content

PHP array() section improvement


Recommended Posts

Hi

 

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 post
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 post
Share on other sites
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...