Last active
August 29, 2015 14:19
-
-
Save bogomolov-dev/cb2e102f2eb752849c21 to your computer and use it in GitHub Desktop.
Kommagetrennte Liste in ein Array umwandeln und jeden Wert validieren
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
<?php | |
function getFormatedArray($string) { | |
$result = array(); | |
if (strpos($string, ',') !== false) { | |
$substrings = explode(',', $string); | |
foreach ($substrings as $substring) { | |
if (trim($substring) != '') { | |
$result[] = strtoupper(trim($substring)); | |
} | |
} | |
if (!count($result)) { | |
return 'ERROR'; | |
} | |
} | |
else { | |
$result[] = $string; | |
} | |
return $result; | |
} |
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
<?php | |
$result = array(); | |
if (strpos($string, ',') !== false) { | |
$substrings = explode(',', $string); | |
// [...] | |
} | |
else { | |
$result[] = $string; | |
} |
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
<?php | |
function getFormatedArray($string) { | |
$result = array(); | |
$substrings = explode(',', $string); | |
foreach ($substrings as $substring) { | |
if (trim($substring) != '') { | |
$result[] = strtoupper(trim($substring)); | |
} | |
} | |
if (!count($result)) { | |
return 'ERROR'; | |
} | |
return $result; | |
} |
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
<?php | |
function getFormatedArray($string) { | |
$result = explode(',', $string); | |
array_walk($result, function(&$substring, $key) { | |
$substring = strtoupper(trim($substring)); | |
}); | |
if (!count($result)) { | |
return 'ERROR'; | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment