Can i parse any of these strings in array with explode()
?
The array look like this
$array = [
'North AmericaWed 20:00',
'North AmericaWed 20:00',
'New ZealandTue 14:00',
'IndonesiaThu 08:00'
];
I want to get country name without days attached to it.
This is the php
code I thought of:
foreach($array as $string){
$parse = explode('any days' , $string);
$result = $parse[0];
}
and the result is :
North America
New Zealand
Indonesia
Thanks for the help everyone!
$array = [
'North AmericaWed 20:00',
'North AmericaWed 20:00',
'New ZealandTue 14:00',
'IndonesiaThu 08:00'
];
foreach($array as $string){
$country = preg_replace('/[0-9]*:[0-9]*+/', '', $string);
echo substr($country,0,-4).'<br/>';
}
Its very odd to code but, If you really need this,here is the way
<?php
$array = [
'North AmericaWed 20:00',
'North AmericaWed 20:00',
'New ZealandTue 14:00',
'IndonesiaThu 08:00'
];
$countries = array();
foreach($array as $string){
//$parse = explode('Wed ' , $string);
$parse = preg_split('/Mon |Tue |Wed |Thu |Fri |Sat |Sun /',$string);
$countries[] = $parse[0]."
";
}
$countries = array_unique($countries);
print_r($countries);
?>
Check demo : https://eval.in/620874
Output is :
Array
(
[0] => North America
[2] => New Zealand
[3] => Indonesia
)
I suggest change your code from where you are creating above string(country+day and time
)