简体   繁体   中英

PHP Shuffle Unique Values from array

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!

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

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM