I have an array in php as follows:-
$arrEquip = array("None", "Bandolier", "Canteen", "Satchel");
What I want to output is the following:-
None
Bandolier
Bandolier; Canteen
Bandolier; Canteen; Satchel
Canteen
Canteen; Satchel
Satchel
Basically each array element needs to have every other array element listed out after it.
I thought that creating an associative multidimensional array would work. Doing a foreach loop which creates the initial keys and then running through the single array again for the values. But I don't know how to combine them all together.
The single array could have any number of elements in it.
EDIT: Sorry, forgot the php code
$arrEquip = array("None", "Bandolier", "Canteen", "Satchel");
$rowCount = count($arrEquip);
$keyVal = "";
$i = 0;
foreach ($arrEquip as $key) {
$keyVal = "";
if (strtoupper($key) !== "NONE") {
for ($y = ($i + 1); $y < $rowCount; $y++) {
$keyVal = $keyVal . $arrEquip[$y] . "; ";
}
}
$arrOutput[$key] = $keyVal;
$i++;
}
Output is:-
Array
(
[None] =>
[Bandolier] => Canteen; Satchel;
[Canteen] => Satchel;
[Satchel] =>
)
EDIT2: Just realised my desired output is wrong. Should be:-
Array
(
[0] => None
[1] => Bandolier
[2] => Bandolier; Canteen
[3] => Bandolier; Canteen; Satchel
[4] => Bandolier; Satchel
[5] => Canteen
[6] => Canteen; Satchel
[7] => Satchel
)
Sorry for the mix up.