-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
32f91df
commit 217dc4a
Showing
5 changed files
with
111 additions
and
11 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
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
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,61 @@ | ||
<?php | ||
|
||
namespace ResonantCore\PHPFuture; | ||
|
||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 Resonant Core, LLC | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
class Utility | ||
{ | ||
/** | ||
* Return the values from a single column in the input array | ||
* | ||
* @param array $array A multi-dimensional array (record set) from which to pull a column of values. | ||
* @param string|int $column_key The column of values to return. | ||
* @param string|int|null $index_key The column to use as the index/keys for the returned array. | ||
* | ||
* @return array | ||
*/ | ||
public static function arrayColumn(array $array, $column_key, $index_key = null) | ||
{ | ||
$aReturn = []; | ||
if ($column_key === null) { | ||
// No column key? Grab the whole row... | ||
if ($index_key === null) { | ||
return $array; | ||
} | ||
foreach ($array as $sub) { | ||
$aReturn[$sub[$index_key]] = $sub; | ||
} | ||
} elseif (empty($index_key)) { | ||
foreach ($array as $sub) { | ||
$aReturn[] = $sub[$column_key]; | ||
} | ||
} else { | ||
foreach ($array as $sub) { | ||
$aReturn[$sub[$index_key]] = $sub[$column_key]; | ||
} | ||
} | ||
return $aReturn; | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
use \ResonantCore\PHPFuture as Future; | ||
|
||
class TestSecurity extends PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @covers \ResonantCore\PHPFuture\Utilty::arrayColumn() | ||
*/ | ||
public function testArrayColumn() | ||
{ | ||
$x = [ | ||
['a' => 1, 'b' => 1], | ||
['a' => 2, 'b' => 3], | ||
['a' => 3, 'b' => 2] | ||
]; | ||
|
||
$y = [ | ||
1 => 1, | ||
2 => 3, | ||
3 => 2 | ||
]; | ||
|
||
$this->assertEquals( | ||
$y, | ||
Future\Utility::arrayColumn($x, 'b', 'a') | ||
); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,7 +2,6 @@ PHP 5.5 | |
|
||
FUNCTIONS | ||
========= | ||
array_column() | ||
curl_escape() | ||
curl_unescape() | ||
pg_escape_literal() | ||
|