New version submitted by TomB
[carbonphp.git] / Documentation / utilities / array.html
blob2e09648ff74f0e02f083e13571e151c5b29a7661
1 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
2 <head>
3 <title>CarbonPHP Documentation</title>
4 <style type="text/css">
5 * {
6 margin: 0;
7 padding: 0;
10 a, a:hover {
11 background: transparent;
12 border-bottom: 1px dotted #666;
13 color: #666;
14 text-decoration: none;
17 a:hover {
18 border: 0;
21 html {
22 font-family: "Lucida Sans Unicode", "Lucida Grande";
23 font-size: 14px;
26 body {
27 background: #fff;
28 color: #666;
31 h1 {
32 font-size: 15px;
33 font-weight: bold;
34 margin: 0 0 5px 0;
37 h2 {
38 font-size: 13px;
39 font-weight: bold;
40 margin: 5px 0 5px 0;
43 ol, ul {
44 margin: 10px 0 10px 0;
45 list-style-position: inside;
48 p {
49 margin: 5px 0 5px 0;
52 .content {
53 border: 1px dotted #444;
54 margin: 10px;
55 padding: 10px;
56 text-align: justify;
57 width: 700px;
60 .example {
61 border: 1px solid #ccc;
62 background: #eee;
63 margin: 10px;
64 padding: 10px;
65 text-align: left;
67 </style>
68 </head>
70 <body>
71 <div class="content">
72 <h1>Array Utility</h1>
74 <p>The Array utlity contains functions that help when working with arrays. You load this utility using the
75 following piece of code.</p>
77 <div class="example">
78 $this->load->utility('array');
79 </div>
80 </div>
82 <div class="content">
83 <h1>element()</h1>
85 <p>This lets you fetch an item from the array. The function tests whether the array index is set and whether
86 it has a value. If a value exists it is returned. If a value does not exist if returns <b>false</b>, or whatever
87 is specified in the default value parameter.</p>
89 <div class="example">
90 $array = array('color' =>; 'red', 'shape' => 'round', 'size' => '');<br />
91 <br />
92 // returns "red"<br />
93 echo element('color', $array);<br />
94 <br />
95 // returns NULL<br />
96 echo element('size', $array, NULL);
97 </div>
98 </div>
100 <div class="content">
101 <h1>random_element()</h1>
103 <p>Takes an array as input and returns a random element from it.</p>
105 <div class="example">
106 $quotes = array(<br />
107 &nbsp;&nbsp;&nbsp;&nbsp;"I find that the harder I work, the more luck I seem to have. - Thomas Jefferson",<br />
108 &nbsp;&nbsp;&nbsp;&nbsp;"Don't stay in bed, unless you can make money in bed. - George Burns",<br />
109 &nbsp;&nbsp;&nbsp;&nbsp;"We didn't lose the game; we just ran out of time. - Vince Lombardi",<br />
110 &nbsp;&nbsp;&nbsp;&nbsp;"If everything seems under control, you're not going fast enough. - Mario Andretti",<br />
111 &nbsp;&nbsp;&nbsp;&nbsp;"Reality is merely an illusion, albeit a very persistent one. - Albert Einstein",<br />
112 &nbsp;&nbsp;&nbsp;&nbsp;"Chance favors the prepared mind - Louis Pasteur"<br />
113 );<br />
114 <br />
115 echo random_element($quotes);<br />
116 </div>
117 </div>
118 </body>
120 </html>