-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 56a2fbe
Showing
284 changed files
with
9,565 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/** | ||
* Definition and Usage: | ||
* The array change key case() function returns an array | ||
* with all array KEYS in lower case or upper case. | ||
* | ||
* | ||
* Syntax: | ||
* array_change_key_case(array, case) | ||
* | ||
* array - Required. Specifies the array to use | ||
* case - Optional. Possible values | ||
* 1. CASE_LOWER - Default value. Changes the keys to lowercase | ||
* 2. CASE_UPPER - Changes the keys to uppercase | ||
* | ||
*/ | ||
|
||
// Example 1: | ||
$userAges = array("Peter" => "35", "Ben" => "37", "Joe" => "43"); | ||
|
||
echo '<pre>'; | ||
print_r(array_change_key_case($userAges, CASE_UPPER)); | ||
print_r(array_change_key_case($userAges, CASE_LOWER)); | ||
print_r(array_change_key_case($userAges)); | ||
echo '</pre>'; | ||
|
||
/** | ||
* The output of the code above will be: | ||
* Array | ||
* ( | ||
* [PETER] => 35 | ||
* [BEN] => 37 | ||
* [JOE] => 43 | ||
* ) | ||
* | ||
* Array | ||
* ( | ||
* [peter] => 35 | ||
* [ben] => 37 | ||
* [joe] => 43 | ||
* ) | ||
* | ||
* Array | ||
* ( | ||
* [peter] => 35 | ||
* [ben] => 37 | ||
* [joe] => 43 | ||
* ) | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/** | ||
* Definition and Usage: | ||
* The array_chunk() function splits an array | ||
* into chunks of new arrays. | ||
* | ||
* | ||
* Syntax: | ||
* array_chunk(array, size, preserve_key) | ||
* | ||
* array - Required. Specifies the array to use | ||
* size - Required. An integer that specifies the size of each chunk | ||
* preserve_key - Optional. Possible values: | ||
* 1. true - Preserves the keys | ||
* 2. false - Default. Reindexes the chunk numerically | ||
* | ||
*/ | ||
|
||
// Example 1: | ||
$users = array("Peter" => "35", "Ben" => "37", "Joe" => "43", "Harry" => "50"); | ||
|
||
echo '<pre>'; | ||
print_r(array_chunk($users, 3, true)); | ||
print_r(array_chunk($users, 2, false)); | ||
echo '</pre>'; | ||
|
||
/** | ||
* The output of the code above will be: | ||
* Array | ||
* ( | ||
* [0] => Array | ||
* ( | ||
* [Peter] => 35 | ||
* [Ben] => 37 | ||
* ) | ||
* [1] => Array | ||
* ( | ||
* [Joe] => 43 | ||
* [Harry] => 50 | ||
* ) | ||
* ) | ||
* | ||
* Array | ||
* ( | ||
* [0] => Array | ||
* ( | ||
* [0] => 35 | ||
* [1] => 37 | ||
* ) | ||
* [1] => Array | ||
* ( | ||
* [0] => 43 | ||
* [1] => 50 | ||
* ) | ||
* ) | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/** | ||
* Definition and Usage: | ||
* The array_column() function returns the values from | ||
* a single column in the input array. | ||
* | ||
* | ||
* Syntax: | ||
* array_column(array, column_key, index_key) | ||
* | ||
* array - Required. Specifies the multi-dimensional array (record-set) | ||
* to use. As of PHP 7.0, this can also be an array of objects. | ||
* column_key - Required. An integer key or a string key name of the column | ||
* of values to return. This parameter can also be NULL to return | ||
* complete arrays (useful together with index_key to re-index the array). | ||
* index_key - Optional. The column to use as the index/keys for the returned array. | ||
* | ||
*/ | ||
|
||
// Example 1: | ||
$users = array( | ||
array( | ||
'id' => 5698, | ||
'first_name' => 'Peter', | ||
'last_name' => 'Burgman', | ||
), | ||
array( | ||
'id' => 4767, | ||
'first_name' => 'Ben', | ||
'last_name' => 'Smith', | ||
), | ||
array( | ||
'id' => 3809, | ||
'first_name' => 'John', | ||
'last_name' => 'Doe', | ||
) | ||
); | ||
|
||
$lastNames = array_column($users, 'last_name'); | ||
|
||
echo '<pre>'; | ||
print_r($lastNames); | ||
echo '</pre>'; | ||
|
||
/** | ||
* The output of the code above will be: | ||
* Array | ||
* ( | ||
* [0] => Burgman | ||
* [1] => Smith | ||
* [2] => Doe | ||
* ) | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/** | ||
* Definition and Usage: | ||
* The array_combine() function creates an array by using | ||
* the elements from one "keys" array and one "values" array. | ||
* | ||
* | ||
* Syntax: | ||
* array_combine(keys, values) | ||
* | ||
* keys - Required. Array of keys | ||
* values - Required. Array of values | ||
* | ||
*/ | ||
|
||
// Example 1: | ||
$users = ['Peter', 'Smith', 'John']; | ||
$ages = [35, 42, 29]; | ||
|
||
$combine = array_combine($ages, $users); | ||
|
||
echo '<pre>'; | ||
print_r($combine); | ||
echo '</pre>'; | ||
|
||
/** | ||
* The output of the code above will be: | ||
* Array | ||
* ( | ||
* [Peter] => 35 | ||
* [Smith] => 42 | ||
* [John] => 29 | ||
* ) | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/** | ||
* Definition and Usage: | ||
* The array_count_values() function counts all the values of an array. | ||
* | ||
* | ||
* Syntax: | ||
* array_count_values(array) | ||
* | ||
*/ | ||
|
||
// Example 1: | ||
$fruits = ['Apple', 'Mango', 'Banana', 'Lemon', 'Apple', 'Orange', 'Strawberry', 'Mango', 'Apple']; | ||
|
||
echo '<pre>'; | ||
print_r(array_count_values($fruits)); | ||
echo '</pre>'; | ||
|
||
/** | ||
* The output of the code above will be: | ||
* Array | ||
* ( | ||
* [Apple] => 2 | ||
* [Mango] => 2 | ||
* [Banana] => 1 | ||
* [Lemon] => 1 | ||
* [Orange] => 1 | ||
* [Strawberry] => 1 | ||
* ) | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/** | ||
* Definition and Usage: | ||
* The array_diff() function compares the values of | ||
* two (or more) arrays, and returns the differences. | ||
* | ||
* | ||
* Syntax: | ||
* array_diff(array1, array2, array3, ...) | ||
* | ||
*/ | ||
|
||
// Example 1: | ||
$arr1 = array("a" => "red", "b" => "green", "c" => "blue", "d" => "yellow"); | ||
$arr2 = array("e" => "red", "f" => "green", "g" => "blue"); | ||
|
||
$result = array_diff($arr1, $arr2); | ||
|
||
echo '<pre>'; | ||
print_r($result); | ||
echo '</pre>'; | ||
|
||
/** | ||
* The output of the code above will be: | ||
* Array | ||
* ( | ||
* [d] => yellow | ||
* ) | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/** | ||
* Definition and Usage: | ||
* The array_fill() function fills an array with values. | ||
* | ||
* | ||
* Syntax: | ||
* array_fill(index, number, value) | ||
* | ||
* index - Required. The first index of the returned array | ||
* number - Required. Specifies the number of elements to insert | ||
* value - Required. Specifies the value to use for filling the array | ||
* | ||
*/ | ||
|
||
// Example 1: | ||
$result = array_fill(1, 3, "blue"); | ||
|
||
echo '<pre>'; | ||
print_r($result); | ||
echo '</pre>'; | ||
|
||
/** | ||
* The output of the code above will be: | ||
* Array | ||
* ( | ||
* [2] => blue | ||
* [3] => blue | ||
* [4] => blue | ||
* [5] => blue | ||
* ) | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/** | ||
* Definition and Usage: | ||
* The array_filter() function filters the values | ||
* of an array using a callback function. | ||
* | ||
* | ||
* Syntax: | ||
* array_filter(array, callbackfunction, flag) | ||
* | ||
* array - Required. Specifies the array to filter | ||
* callbackfunction - Optional. Specifies the callback function to use | ||
* flag - Optional. Specifies what arguments are sent to callback: | ||
* | ||
* ARRAY_FILTER_USE_KEY - pass key as the only argument to callback (instead of the value) | ||
* ARRAY_FILTER_USE_BOTH - pass both value and key as arguments to callback (instead of the value) | ||
* | ||
*/ | ||
|
||
// Example 1: | ||
$number = [1, 2, 3, 4, 5, 6, 7, 8, 9]; | ||
|
||
$oddNum = array_filter($number, | ||
function ($num) { | ||
if ($num % 2 == 1) { | ||
return $num; | ||
} | ||
} | ||
); | ||
|
||
$evenNum = array_filter($number, | ||
function ($num) { | ||
if ($num % 2 === 0) { | ||
return $num; | ||
} | ||
} | ||
); | ||
|
||
|
||
echo '<pre>'; | ||
print_r($oddNum); | ||
print_r($evenNum); | ||
echo '</pre>'; | ||
|
||
/** | ||
* The output of the code above will be: | ||
* Array | ||
* ( | ||
* [1] => 2 | ||
* [3] => 4 | ||
* [5] => 6 | ||
* [7] => 8 | ||
* ) | ||
* | ||
* Array | ||
* ( | ||
* [0] => 1 | ||
* [2] => 3 | ||
* [4] => 5 | ||
* [6] => 7 | ||
* [8] => 9 | ||
* ) | ||
*/ |
Oops, something went wrong.