Get the 2nd value of a variable that has 7 values separated by comma
In a variable $price
I have those values separated by comma. Each one represent a day.
1st value,2nd value,3rd value,4th value,5th value,6th value,7th value
If I have a $day
variable can I find the value ? What I mean is l开发者_C百科ike
if ($day == "Monday")
echo the 2nd value of $price
.
$pricePerDay = array_combine(array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'),
explode(',', $price));
echo $pricePerDay['Mon'];
You can look up the function explode(',',$price);
and use that to help you out. You'll need a loop to get through the values and determine if it is the specific day.
Try this
$var="1st value,2nd value,3rd value,4th value,5th value,6th value,7th value";
$var_exploded=explode(",",$var);
if you want second value
echo $var_exploded[1];
精彩评论