EnexoOnoma
EnexoOnoma

Reputation: 8836

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 like if ($day == "Monday") echo the 2nd value of $price.

Upvotes: 2

Views: 94

Answers (3)

deceze
deceze

Reputation: 522145

$pricePerDay = array_combine(array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'),
                             explode(',', $price));
echo $pricePerDay['Mon'];

Upvotes: 1

Wasim Karani
Wasim Karani

Reputation: 8886

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];

Upvotes: 0

tlunter
tlunter

Reputation: 724

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.

Upvotes: 0

Related Questions