Posted By

Piotrek290 on 01/02/10


Tagged

select array String


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

jose_506
jlan


array_select(), arrays/strings


 / Published in: PHP
 

  1. <?php
  2. function print_pre($code){
  3. print "<pre>";
  4. print_r($code);
  5. print "</pre>";
  6. }
  7.  
  8. function array_select(){
  9. $o=array();
  10.  
  11. for($i=1;$i<$c;++$i)if(($g[0]?is_array($g[$i]):!is_array($g[$i])))array_push($o,$g[$i]);
  12. return $o;
  13. }
  14.  
  15. // Ex. 1
  16. // Select only strings
  17. // return: val1, val2, val3, val8, val9
  18. print_pre(array_select(
  19. false,
  20. "val1",
  21. "val2",
  22. "val3",
  23. "val4",
  24. "val5"
  25. ),
  26. "val6",
  27. "val7"
  28. ),
  29. "val8",
  30. "val9"
  31. ));
  32.  
  33. // Ex. 2
  34. // Select only arrays
  35. // return: array('val4', 'val5'), array('val6', 'val7')
  36. print_pre(array_select(
  37. false,
  38. "val1",
  39. "val2",
  40. "val3",
  41. "val4",
  42. "val5"
  43. ),
  44. "val6",
  45. "val7"
  46. ),
  47. "val8",
  48. "val9"
  49. ));
  50.  
  51. ?>

Report this snippet  

You need to login to post a comment.