PHP从数组中随机排列唯一值

时间:2018-10-13 19:37:55

标签: php arrays

我需要从数组获取此输出

$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

谢谢!

1 个答案:

答案 0 :(得分:0)

我希望这是您要寻找的。很简单,但是根据您的问题:就足够了。

<?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/>";
      }
    }
  }

?>