I would like to know how to know how to split the string by | and - and and display the values in php
I have string which i need to split by |and then - and display the value in php
<?php
$string = 'city-3|country-4';
$str1 = explode('|', $string, 2);
foreach ($str1 as $item) {
$meal = explode('-', $string, 2);
if (meal[0]=="city")
{
echo "city duration " + meal[1]
}
else if (meal[0]=="country")
{
echo "country duration " + meal[1]
}
}
?>
ExpectedOutput
city duration 3
country duration 4