1// array demo
2
3public $gender = array(
4 1 => 'Male',
5 2 => 'Female',
6 3 => 'Other',
7);
8
9$gen = 1;
10
11if ($gen == array_search('Male', $this->gender)) {
12 $gender = __d('member', 'male');
13
14} elseif ($gen == array_search('Female', $this->gender)) {
15 $gender = __d('member', 'female');
16
17}
18
19
1$array = [
2 'clothes' => 't-shirt',
3 'size' => 'medium',
4 'color' => 'blue',
5];
6
7extract($array);
8
9echo("$clothes $size $color"); // t-shirt medium blue
10
1function lookup($array, $key) {
2
3 //loop through all values in array
4 foreach($array as $values) {
5
6 //if 'key' value matches `$key`, return 'value' value.
7 if($values['key'] == $key) {
8 return $values['value'];
9 }
10
11 }
12
13 //if nothing has been returned, return empty string
14 return "";
15}
16