0

I need to get this output from array

$properties = array(
    1 => array('one', 'two'),
    2 => array('red', 'blue'),
    3 => array('active', 'not-active'),
);
  • one_red_active
  • one_red_not-active
  • one_blue_active
  • one_blue_not-active
  • two_red_active
  • two_red_not-active
  • two_blue_active
  • two_blue_not-active

Thx!

Evgeny
  • 1
  • 1
    Welcome to Stack Overflow. What have you tried so far ? Please update your question with your code attempt. – Madhur Bhaiya Oct 13 '18 at 19:38
  • Maybe [this question](https://stackoverflow.com/questions/6311779) will help. – msg Oct 13 '18 at 19:42
  • your question is a bit vague... what are you looking for? is it the cleanest way of combining all the possible array values with an underscore? the first thing that comes into my mind is nested for each... or with an iterator variable – sietse85 Oct 13 '18 at 19:52
  • Possible duplicate of [How can I sort arrays and data in PHP?](https://stackoverflow.com/questions/17364127/how-can-i-sort-arrays-and-data-in-php) – SeaWarrior404 Oct 13 '18 at 21:24

1 Answers1

0

I hope this is what you are looking for. Simple, but based on your question: it should suffice.

<?php

  $properties = array(
    1 => array('one', 'two'),
    2 => array('red', 'blue'),
    3 => array('active', 'not-active'),
  );

  /*echo "<pre>";
  print_R($properties);
  echo "</pre>";*/
  //Not needed but stil useful for troubleshooting.

  foreach ($properties[1] as $value_array_one) {
    foreach ($properties[2] as $value_array_two) {
      foreach ($properties[3] as $value_array_three) {
        echo $value_array_one . "_" . $value_array_two . "_" . $value_array_three . "<br/>";
      }
    }
  }

?>
Riverans
  • 336
  • 1
  • 12