Guest User

Untitled

a guest
Jan 17th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. $fruits = array(
  2. array(
  3. 'color' => 'red',
  4. 'name' => 'apple'
  5. ),
  6. array(
  7. 'color' => 'red',
  8. 'name' => 'cherry'
  9. ),
  10. array(
  11. 'color' => 'yellow',
  12. 'name' => 'banana'
  13. )
  14. );
  15.  
  16. red
  17. 1. apple
  18. 2. cherry
  19.  
  20. yellow
  21. 1. banana
  22.  
  23. {foreach from=$fruits item=fruit}
  24. {assign var="current_color" value=$fruit.color}
  25. <h1>{$current_color}</h1>
  26. <ol>
  27. {while $current_color === $fruit.color}
  28. <li>{$fruit.name}</li>
  29. {assign var="fruit" value=$fruits|next}
  30. {/while}
  31. </ol>
  32. {/foreach}
  33.  
  34. red
  35. 1. apple
  36. 2. cherry
  37.  
  38. red
  39. 1. cherry
  40.  
  41. yellow
  42. 1. banana
  43.  
  44. {for $iteration=0 to $fruits|count - 1}
  45. {assign var="current_color" value=$fruits.{$iteration}.color}
  46. <h1>{$current_color}</h1>
  47. <ol>
  48. {while $current_color === $fruits.{$iteration}.color}
  49. <li>{$fruits.{$iteration}.name}</li>
  50. {assign var="iteration" value=$iteration + 1}
  51. {/while}
  52. {assign var="iteration" value=$iteration - 1}
  53. </ol>
  54. {/for}
Add Comment
Please, Sign In to add comment