Commit 71e3de37 authored by Carsten  Rose's avatar Carsten Rose
Browse files

OnArray.php: detArrayItems() - new $skipEmpty, $skipZero

parent 515d80d6
......@@ -29,7 +29,7 @@ class OnArray {
* @param array $dataArray
* @param string $keyValueGlue
* @param string $rowGlue
* @param string $encloseValue - char (or string) to enclose the value with.
* @param string $encloseValue - char (or string) to enclose the value with.
* @return string
*/
public static function toString(array $dataArray, $keyValueGlue = '=', $rowGlue = '&', $encloseValue = '') {
......@@ -213,13 +213,19 @@ class OnArray {
* @param bool $createMissing
* @return array
*/
public static function getArrayItems(array $src, array $keyNames, $createMissing = false) {
public static function getArrayItems(array $src, array $keyNames, $createMissing = false, $skipZero = false, $skipEmpty = false) {
$new = array();
// Extract necessary elements
foreach ($keyNames as $key) {
if (isset($src[$key])) {
$new[$key] = $src[$key];
if (($src[$key] === '' && $skipEmpty) || ($src[$key] == '0' && $skipZero)) {
$copy = false;
} else {
$new[$key] = $src[$key];
}
} elseif ($createMissing == true) {
$new[$key] = '';
}
......@@ -263,10 +269,10 @@ class OnArray {
* @param $replace
* @return array
*/
public static function arrayValueReplace(array $src, $search, $replace ) {
public static function arrayValueReplace(array $src, $search, $replace) {
$new = array();
foreach($src AS $key => $element) {
foreach ($src AS $key => $element) {
$new[$key] = str_replace($search, $replace, $element);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment