Jump to content

linearise a multidimensional array into single array of strings


discusster

Recommended Posts

Can someone help me out please?

I'm needing some advice on how to take a multidimensional array (which you can view here: http://discusster.textdriven.com/sandbox/index.php) and break it down into a single array with the current array values joined into strings?

In case this isn't clear, I'm trying to create a drop-down menu with every possible combination of the following terms: [i]sad[/i], [i]tearful [/i]and [i]desperate[/i]. So at the moment I've got my multidimensional array displaying each array with the various combinations, I just need to create the options to go into my <select> form field, like so:

<select>
  <option>sad,</option>
  <option>tearful,</option>
  <option>sad,tearful,</option>
  <option>desperate,</option>
  <option>sad,desperate,</option>
  <option>tearful,desperate,</option>
  <option>sad,tearful,desperate,</option>
</select>

Anyone help?
Hi Jenk,

Many thanks for the reply. Are you suggesting using [i]implode[/i]? I was messing about with that but couldn't get what I was looking for. If that's the way to do it then am happy with that if someone can show me the way how.

Basically I've got six arrays, each one holds a combination of values which I'd like to join together as a string; so with reference to the example at http://discusster.textdriven.com/sandbox/index.php the ideal outcome would be an array like this:

[code]
<?php

$array = array{
  "sad,",
  "tearful,",
  "sad,tearful,",
  "desperate,",
  "sad,desperate,",
  "tearful,desperate,",
  "sad,tearful,desperate,",
};

?>
[/code]

NB. To avoid any confusion, the values already all have a comma after each term - it's coming from a database like this)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.