PHP - Filter an array string alphabetically
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have an array of strings
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
I want to retrieve all the strings that starts with letter A, then B, then C, and so on for each alphabet letters.
What is the best way to do it avoing useless code repetitions?
php arrays filter
add a comment |
I have an array of strings
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
I want to retrieve all the strings that starts with letter A, then B, then C, and so on for each alphabet letters.
What is the best way to do it avoing useless code repetitions?
php arrays filter
9
have you tried doing it yourself?
– Yousaf
Nov 22 '18 at 12:09
Question, do you have it?
– u_mulder
Nov 22 '18 at 12:13
1
Use array_filter()
– Magnus Eriksson
Nov 22 '18 at 12:17
add a comment |
I have an array of strings
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
I want to retrieve all the strings that starts with letter A, then B, then C, and so on for each alphabet letters.
What is the best way to do it avoing useless code repetitions?
php arrays filter
I have an array of strings
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
I want to retrieve all the strings that starts with letter A, then B, then C, and so on for each alphabet letters.
What is the best way to do it avoing useless code repetitions?
php arrays filter
php arrays filter
edited Nov 23 '18 at 16:12
albertovalerio
asked Nov 22 '18 at 12:07
albertovalerioalbertovalerio
42
42
9
have you tried doing it yourself?
– Yousaf
Nov 22 '18 at 12:09
Question, do you have it?
– u_mulder
Nov 22 '18 at 12:13
1
Use array_filter()
– Magnus Eriksson
Nov 22 '18 at 12:17
add a comment |
9
have you tried doing it yourself?
– Yousaf
Nov 22 '18 at 12:09
Question, do you have it?
– u_mulder
Nov 22 '18 at 12:13
1
Use array_filter()
– Magnus Eriksson
Nov 22 '18 at 12:17
9
9
have you tried doing it yourself?
– Yousaf
Nov 22 '18 at 12:09
have you tried doing it yourself?
– Yousaf
Nov 22 '18 at 12:09
Question, do you have it?
– u_mulder
Nov 22 '18 at 12:13
Question, do you have it?
– u_mulder
Nov 22 '18 at 12:13
1
1
Use array_filter()
– Magnus Eriksson
Nov 22 '18 at 12:17
Use array_filter()
– Magnus Eriksson
Nov 22 '18 at 12:17
add a comment |
5 Answers
5
active
oldest
votes
You can create a temporary multidimensional array with first letter as index. Try -
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
foreach($cities as $city) {
$first = substr($city, 0, 1);
$temp_cities[$first] = $city;
}
var_dump($temp_cities);
Output
array(8) {
["N"]=>
array(1) {
[0]=>
string(8) "New York"
}
["B"]=>
array(1) {
[0]=>
string(6) "Boston"
}
["L"]=>
array(1) {
[0]=>
string(11) "Los Angeles"
}
["C"]=>
array(2) {
[0]=>
string(10) "Cincinnati"
[1]=>
string(7) "Chicago"
}
["H"]=>
array(1) {
[0]=>
string(7) "Houston"
}
["P"]=>
array(1) {
[0]=>
string(12) "Philadelphia"
}
["D"]=>
array(1) {
[0]=>
string(6) "Dallas"
}
["S"]=>
array(1) {
[0]=>
string(7) "Seattle"
}
}
To find cities start with 'C' do - var_dump($temp_cities['C'])
Thanks that solves my question and seems to me the best way to do it. My point was to avoid useless code repetitions. Thanks again.
– albertovalerio
Nov 23 '18 at 15:55
add a comment |
Please try this
<?php
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
$new_array = ;
$search_string = 'C'; // Letter to search
foreach ($cities as $city) {
if (strpos($city, $search_string) === 0) {
$new_array = $city;
}
}
print_r($new_array);// New array will contian list of identified cities
?>
add a comment |
usort($cities, function($a, $b){
return $a <=> $b;
});
4
Or, y'know, justsort($cities)
. But either way sorting isn't what the question is about.
– iainn
Nov 22 '18 at 12:15
add a comment |
If I understand correctly, you're trying to create 26 arrays, one for each letter of the alphabet, each array containing cities starting with that letter.
<?php
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
//Our 26 arrays
$arrA = array();
$arrB = array();
$arrC = array();
$arrD = array();
$arrE = array();
$arrF = array();
$arrG = array();
$arrH = array();
$arrI = array();
$arrJ = array();
$arrK = array();
$arrL = array();
$arrM = array();
$arrN = array();
$arrO = array();
$arrP = array();
$arrQ = array();
$arrR = array();
$arrS = array();
$arrT = array();
$arrU = array();
$arrV = array();
$arrW = array();
$arrX = array();
$arrY = array();
$arrZ = array();
//Fill the array for that city.
foreach ($cities as $city){
$key = substr($city, 0, 1);
${"arr".$key} = $city;
}
//Let's just test this worked.
var_dump($arrC);
var_dump($arrB);
var_dump($arrN);
?>
5
Using multidimensional array is better than 26 separate variable
– Mohammad
Nov 22 '18 at 12:53
@Mohammad I agree that would be better, but it's not what the OP asked for.
– Ben Hillier
Nov 26 '18 at 9:41
add a comment |
You can simply sort array with
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
sort($cities);
Please post documentation links to the actual manual rather than a third party site
– Nick
Nov 24 '18 at 6:39
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430676%2fphp-filter-an-array-string-alphabetically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can create a temporary multidimensional array with first letter as index. Try -
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
foreach($cities as $city) {
$first = substr($city, 0, 1);
$temp_cities[$first] = $city;
}
var_dump($temp_cities);
Output
array(8) {
["N"]=>
array(1) {
[0]=>
string(8) "New York"
}
["B"]=>
array(1) {
[0]=>
string(6) "Boston"
}
["L"]=>
array(1) {
[0]=>
string(11) "Los Angeles"
}
["C"]=>
array(2) {
[0]=>
string(10) "Cincinnati"
[1]=>
string(7) "Chicago"
}
["H"]=>
array(1) {
[0]=>
string(7) "Houston"
}
["P"]=>
array(1) {
[0]=>
string(12) "Philadelphia"
}
["D"]=>
array(1) {
[0]=>
string(6) "Dallas"
}
["S"]=>
array(1) {
[0]=>
string(7) "Seattle"
}
}
To find cities start with 'C' do - var_dump($temp_cities['C'])
Thanks that solves my question and seems to me the best way to do it. My point was to avoid useless code repetitions. Thanks again.
– albertovalerio
Nov 23 '18 at 15:55
add a comment |
You can create a temporary multidimensional array with first letter as index. Try -
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
foreach($cities as $city) {
$first = substr($city, 0, 1);
$temp_cities[$first] = $city;
}
var_dump($temp_cities);
Output
array(8) {
["N"]=>
array(1) {
[0]=>
string(8) "New York"
}
["B"]=>
array(1) {
[0]=>
string(6) "Boston"
}
["L"]=>
array(1) {
[0]=>
string(11) "Los Angeles"
}
["C"]=>
array(2) {
[0]=>
string(10) "Cincinnati"
[1]=>
string(7) "Chicago"
}
["H"]=>
array(1) {
[0]=>
string(7) "Houston"
}
["P"]=>
array(1) {
[0]=>
string(12) "Philadelphia"
}
["D"]=>
array(1) {
[0]=>
string(6) "Dallas"
}
["S"]=>
array(1) {
[0]=>
string(7) "Seattle"
}
}
To find cities start with 'C' do - var_dump($temp_cities['C'])
Thanks that solves my question and seems to me the best way to do it. My point was to avoid useless code repetitions. Thanks again.
– albertovalerio
Nov 23 '18 at 15:55
add a comment |
You can create a temporary multidimensional array with first letter as index. Try -
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
foreach($cities as $city) {
$first = substr($city, 0, 1);
$temp_cities[$first] = $city;
}
var_dump($temp_cities);
Output
array(8) {
["N"]=>
array(1) {
[0]=>
string(8) "New York"
}
["B"]=>
array(1) {
[0]=>
string(6) "Boston"
}
["L"]=>
array(1) {
[0]=>
string(11) "Los Angeles"
}
["C"]=>
array(2) {
[0]=>
string(10) "Cincinnati"
[1]=>
string(7) "Chicago"
}
["H"]=>
array(1) {
[0]=>
string(7) "Houston"
}
["P"]=>
array(1) {
[0]=>
string(12) "Philadelphia"
}
["D"]=>
array(1) {
[0]=>
string(6) "Dallas"
}
["S"]=>
array(1) {
[0]=>
string(7) "Seattle"
}
}
To find cities start with 'C' do - var_dump($temp_cities['C'])
You can create a temporary multidimensional array with first letter as index. Try -
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
foreach($cities as $city) {
$first = substr($city, 0, 1);
$temp_cities[$first] = $city;
}
var_dump($temp_cities);
Output
array(8) {
["N"]=>
array(1) {
[0]=>
string(8) "New York"
}
["B"]=>
array(1) {
[0]=>
string(6) "Boston"
}
["L"]=>
array(1) {
[0]=>
string(11) "Los Angeles"
}
["C"]=>
array(2) {
[0]=>
string(10) "Cincinnati"
[1]=>
string(7) "Chicago"
}
["H"]=>
array(1) {
[0]=>
string(7) "Houston"
}
["P"]=>
array(1) {
[0]=>
string(12) "Philadelphia"
}
["D"]=>
array(1) {
[0]=>
string(6) "Dallas"
}
["S"]=>
array(1) {
[0]=>
string(7) "Seattle"
}
}
To find cities start with 'C' do - var_dump($temp_cities['C'])
answered Nov 22 '18 at 12:32
Sougata BoseSougata Bose
26.9k53165
26.9k53165
Thanks that solves my question and seems to me the best way to do it. My point was to avoid useless code repetitions. Thanks again.
– albertovalerio
Nov 23 '18 at 15:55
add a comment |
Thanks that solves my question and seems to me the best way to do it. My point was to avoid useless code repetitions. Thanks again.
– albertovalerio
Nov 23 '18 at 15:55
Thanks that solves my question and seems to me the best way to do it. My point was to avoid useless code repetitions. Thanks again.
– albertovalerio
Nov 23 '18 at 15:55
Thanks that solves my question and seems to me the best way to do it. My point was to avoid useless code repetitions. Thanks again.
– albertovalerio
Nov 23 '18 at 15:55
add a comment |
Please try this
<?php
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
$new_array = ;
$search_string = 'C'; // Letter to search
foreach ($cities as $city) {
if (strpos($city, $search_string) === 0) {
$new_array = $city;
}
}
print_r($new_array);// New array will contian list of identified cities
?>
add a comment |
Please try this
<?php
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
$new_array = ;
$search_string = 'C'; // Letter to search
foreach ($cities as $city) {
if (strpos($city, $search_string) === 0) {
$new_array = $city;
}
}
print_r($new_array);// New array will contian list of identified cities
?>
add a comment |
Please try this
<?php
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
$new_array = ;
$search_string = 'C'; // Letter to search
foreach ($cities as $city) {
if (strpos($city, $search_string) === 0) {
$new_array = $city;
}
}
print_r($new_array);// New array will contian list of identified cities
?>
Please try this
<?php
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
$new_array = ;
$search_string = 'C'; // Letter to search
foreach ($cities as $city) {
if (strpos($city, $search_string) === 0) {
$new_array = $city;
}
}
print_r($new_array);// New array will contian list of identified cities
?>
answered Nov 22 '18 at 12:20
VamsiVamsi
285217
285217
add a comment |
add a comment |
usort($cities, function($a, $b){
return $a <=> $b;
});
4
Or, y'know, justsort($cities)
. But either way sorting isn't what the question is about.
– iainn
Nov 22 '18 at 12:15
add a comment |
usort($cities, function($a, $b){
return $a <=> $b;
});
4
Or, y'know, justsort($cities)
. But either way sorting isn't what the question is about.
– iainn
Nov 22 '18 at 12:15
add a comment |
usort($cities, function($a, $b){
return $a <=> $b;
});
usort($cities, function($a, $b){
return $a <=> $b;
});
answered Nov 22 '18 at 12:14
TsVTsV
45417
45417
4
Or, y'know, justsort($cities)
. But either way sorting isn't what the question is about.
– iainn
Nov 22 '18 at 12:15
add a comment |
4
Or, y'know, justsort($cities)
. But either way sorting isn't what the question is about.
– iainn
Nov 22 '18 at 12:15
4
4
Or, y'know, just
sort($cities)
. But either way sorting isn't what the question is about.– iainn
Nov 22 '18 at 12:15
Or, y'know, just
sort($cities)
. But either way sorting isn't what the question is about.– iainn
Nov 22 '18 at 12:15
add a comment |
If I understand correctly, you're trying to create 26 arrays, one for each letter of the alphabet, each array containing cities starting with that letter.
<?php
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
//Our 26 arrays
$arrA = array();
$arrB = array();
$arrC = array();
$arrD = array();
$arrE = array();
$arrF = array();
$arrG = array();
$arrH = array();
$arrI = array();
$arrJ = array();
$arrK = array();
$arrL = array();
$arrM = array();
$arrN = array();
$arrO = array();
$arrP = array();
$arrQ = array();
$arrR = array();
$arrS = array();
$arrT = array();
$arrU = array();
$arrV = array();
$arrW = array();
$arrX = array();
$arrY = array();
$arrZ = array();
//Fill the array for that city.
foreach ($cities as $city){
$key = substr($city, 0, 1);
${"arr".$key} = $city;
}
//Let's just test this worked.
var_dump($arrC);
var_dump($arrB);
var_dump($arrN);
?>
5
Using multidimensional array is better than 26 separate variable
– Mohammad
Nov 22 '18 at 12:53
@Mohammad I agree that would be better, but it's not what the OP asked for.
– Ben Hillier
Nov 26 '18 at 9:41
add a comment |
If I understand correctly, you're trying to create 26 arrays, one for each letter of the alphabet, each array containing cities starting with that letter.
<?php
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
//Our 26 arrays
$arrA = array();
$arrB = array();
$arrC = array();
$arrD = array();
$arrE = array();
$arrF = array();
$arrG = array();
$arrH = array();
$arrI = array();
$arrJ = array();
$arrK = array();
$arrL = array();
$arrM = array();
$arrN = array();
$arrO = array();
$arrP = array();
$arrQ = array();
$arrR = array();
$arrS = array();
$arrT = array();
$arrU = array();
$arrV = array();
$arrW = array();
$arrX = array();
$arrY = array();
$arrZ = array();
//Fill the array for that city.
foreach ($cities as $city){
$key = substr($city, 0, 1);
${"arr".$key} = $city;
}
//Let's just test this worked.
var_dump($arrC);
var_dump($arrB);
var_dump($arrN);
?>
5
Using multidimensional array is better than 26 separate variable
– Mohammad
Nov 22 '18 at 12:53
@Mohammad I agree that would be better, but it's not what the OP asked for.
– Ben Hillier
Nov 26 '18 at 9:41
add a comment |
If I understand correctly, you're trying to create 26 arrays, one for each letter of the alphabet, each array containing cities starting with that letter.
<?php
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
//Our 26 arrays
$arrA = array();
$arrB = array();
$arrC = array();
$arrD = array();
$arrE = array();
$arrF = array();
$arrG = array();
$arrH = array();
$arrI = array();
$arrJ = array();
$arrK = array();
$arrL = array();
$arrM = array();
$arrN = array();
$arrO = array();
$arrP = array();
$arrQ = array();
$arrR = array();
$arrS = array();
$arrT = array();
$arrU = array();
$arrV = array();
$arrW = array();
$arrX = array();
$arrY = array();
$arrZ = array();
//Fill the array for that city.
foreach ($cities as $city){
$key = substr($city, 0, 1);
${"arr".$key} = $city;
}
//Let's just test this worked.
var_dump($arrC);
var_dump($arrB);
var_dump($arrN);
?>
If I understand correctly, you're trying to create 26 arrays, one for each letter of the alphabet, each array containing cities starting with that letter.
<?php
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
//Our 26 arrays
$arrA = array();
$arrB = array();
$arrC = array();
$arrD = array();
$arrE = array();
$arrF = array();
$arrG = array();
$arrH = array();
$arrI = array();
$arrJ = array();
$arrK = array();
$arrL = array();
$arrM = array();
$arrN = array();
$arrO = array();
$arrP = array();
$arrQ = array();
$arrR = array();
$arrS = array();
$arrT = array();
$arrU = array();
$arrV = array();
$arrW = array();
$arrX = array();
$arrY = array();
$arrZ = array();
//Fill the array for that city.
foreach ($cities as $city){
$key = substr($city, 0, 1);
${"arr".$key} = $city;
}
//Let's just test this worked.
var_dump($arrC);
var_dump($arrB);
var_dump($arrN);
?>
answered Nov 22 '18 at 12:38
Ben HillierBen Hillier
1,7501611
1,7501611
5
Using multidimensional array is better than 26 separate variable
– Mohammad
Nov 22 '18 at 12:53
@Mohammad I agree that would be better, but it's not what the OP asked for.
– Ben Hillier
Nov 26 '18 at 9:41
add a comment |
5
Using multidimensional array is better than 26 separate variable
– Mohammad
Nov 22 '18 at 12:53
@Mohammad I agree that would be better, but it's not what the OP asked for.
– Ben Hillier
Nov 26 '18 at 9:41
5
5
Using multidimensional array is better than 26 separate variable
– Mohammad
Nov 22 '18 at 12:53
Using multidimensional array is better than 26 separate variable
– Mohammad
Nov 22 '18 at 12:53
@Mohammad I agree that would be better, but it's not what the OP asked for.
– Ben Hillier
Nov 26 '18 at 9:41
@Mohammad I agree that would be better, but it's not what the OP asked for.
– Ben Hillier
Nov 26 '18 at 9:41
add a comment |
You can simply sort array with
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
sort($cities);
Please post documentation links to the actual manual rather than a third party site
– Nick
Nov 24 '18 at 6:39
add a comment |
You can simply sort array with
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
sort($cities);
Please post documentation links to the actual manual rather than a third party site
– Nick
Nov 24 '18 at 6:39
add a comment |
You can simply sort array with
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
sort($cities);
You can simply sort array with
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
sort($cities);
edited Nov 27 '18 at 5:31
answered Nov 22 '18 at 12:29
NickNick
53
53
Please post documentation links to the actual manual rather than a third party site
– Nick
Nov 24 '18 at 6:39
add a comment |
Please post documentation links to the actual manual rather than a third party site
– Nick
Nov 24 '18 at 6:39
Please post documentation links to the actual manual rather than a third party site
– Nick
Nov 24 '18 at 6:39
Please post documentation links to the actual manual rather than a third party site
– Nick
Nov 24 '18 at 6:39
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430676%2fphp-filter-an-array-string-alphabetically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
9
have you tried doing it yourself?
– Yousaf
Nov 22 '18 at 12:09
Question, do you have it?
– u_mulder
Nov 22 '18 at 12:13
1
Use array_filter()
– Magnus Eriksson
Nov 22 '18 at 12:17